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",
Params: map[string]string{"hello": "world"},
}
resp, err := client.Do()
POST
client := request.Client{
URL: "https://google.com",
Method: "POST",
Params: map[string]string{"hello": "world"},
Body: []byte(`{"hello": "world"}`),
}
resp, err := client.Do()
Content-Type
client := request.Client{
URL: "https://google.com",
Method: "POST",
ContentType: request.ApplicationXWwwFormURLEncoded, // default is "application/json"
}
resp, err := client.Do()
Authorization
client := request.Client{
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username:"user_xxx",
Password:"pwd_xxx",
}, // xxx:xxx
}
resp, err := client.Do()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
URL string
Method string
Header map[string]string
Params map[string]string
Body []byte
BasicAuth BasicAuth
Timeout time.Duration // second
ContentType ContentType
}
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>
type ContentType ¶
type ContentType string
ContentType Content-Type
const ( // ApplicationJSON application/json ApplicationJSON ContentType = "application/json" // ApplicationXWwwFormURLEncoded application/x-www-form-urlencoded ApplicationXWwwFormURLEncoded ContentType = "application/x-www-form-urlencoded" // MultipartFormData multipart/form-data MultipartFormData ContentType = "multipart/form-data" )
Click to show internal directories.
Click to hide internal directories.