Documentation
¶
Overview ¶
Package request HTTP client for golang
- Make http requests from Golang
- Intercept request and response
- Transform request and response data
GET
client := request.Client{
URL: "https://google.com",
Method: "GET",
Query: map[string]string{"hello": "world"},
}
resp := client.Send()
POST
client := request.Client{
URL: "https://google.com",
Method: "POST",
Query: map[string]string{"hello": "world"},
JSON: []byte(`{"hello": "world"}`),
}
resp := client.Send()
Content-Type
client := request.Client{
URL: "https://google.com",
Method: "POST",
ContentType: request.ApplicationXWwwFormURLEncoded, // default is "application/json"
}
resp := client.Send()
Authorization
client := request.Client{
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username:"user_xxx",
Password:"pwd_xxx",
}, // xxx:xxx
}
resp := client.Send()
Cookies
client := request.Client{
URL: "https://google.com",
Cookies:[]*http.Cookie{
{
Name: "cookie_name",
Value: "cookie_value",
},
},
}
resp := client.Send()
Index ¶
Constants ¶
View Source
const ( // OPTIONS http options OPTIONS = "OPTIONS" // GET http get GET = "GET" // HEAD http head HEAD = "HEAD" // POST http post POST = "POST" // PUT http put PUT = "PUT" // DELETE http delete DELETE = "DELETE" // TRACE http trace TRACE = "TRACE" // CONNECT http connect CONNECT = "CONNECT" // PATCH http patch PATCH = "PATCH" )
View Source
const Version = "v1.0.6"
Version of module github.com/monaco-io/request
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// URL http request url like: https://www.google.com
URL string
// Method http method GET/POST/POST/DELETE ...
Method string
// Header http header
Header map[string]string
// Query params on http url
Query map[string]string
// JSON body as json string/bytes/struct
JSON interface{}
// XML body as xml string/bytes/struct
XML interface{}
// XML body as string
String string
// WWWForm TODO
WWWForm interface{}
// BasicAuth http basic auth with username and password
BasicAuth BasicAuth
// CustomerAuth add Authorization xxx to header
CustomerAuth string
// CustomerAuth add Authorization bearer xxx to header
Bearer string
// Timeout http request timeout
Timeout time.Duration
// TLSTimeout tls timeout
TLSTimeout time.Duration
// DialTimeout dial timeout
DialTimeout time.Duration
// ProxyURL proxy url
ProxyURL string
// Define the proxy function to be used during the transport
ProxyServers map[string]string
// Cookies original http cookies
Cookies []*http.Cookie
// CookiesMap add cookies as map
CookiesMap map[string]string
// TLSConfig tls config on transport
TLSConfig *tls.Config
// Transport http transport
Transport *http.Transport
}
Client Method
Method = "OPTIONS" ; Section 9.2
| "GET" ; Section 9.3
| "HEAD" ; Section 9.4
| "POST" ; Section 9.5
| "PUT" ; Section 9.6
| "DELETE" ; Section 9.7
| "TRACE" ; Section 9.8
| "CONNECT" ; Section 9.9
| extension-method
extension-method = token
token = 1*<any CHAR except CTLs or separators>
Click to show internal directories.
Click to hide internal directories.