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()
Cookies
client := request.Client{ URL: "https://google.com", Cookies:[]*http.Cookie{ { Name: "cookie_name", Value: "cookie_value", }, }, } resp, err := client.Do()
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" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 ProxyURL string ContentType ContentType Cookies []*http.Cookie TLSConfig *tls.Config Transport *http.Transport Req *http.Request // contains filtered or unexported fields }
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" )
type SugaredResp ¶
SugaredResp Sugared response with status code and body data
func (*SugaredResp) Status ¶
func (s *SugaredResp) Status() (status string)
Status get response status code and text, like 200 ok
func (*SugaredResp) StatusCode ¶
func (s *SugaredResp) StatusCode() (code int)
StatusCode get response status code
Click to show internal directories.
Click to hide internal directories.