Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( INFO_CONTINUE = 100 INFO_SWITCHING_PROTOCOL = 101 INFO_PROCESSING = 102 SUCCESS_OK = 200 SUCCESS_CREATED = 201 SUCCESS_ACCEPTED = 202 SUCCESS_NON_AUTHORITATIVE = 203 SUCCESS_NO_CONTENT = 204 SUCCESS_RESET_CONTENT = 205 SUCCESS_PARTIAL_CONTENT = 206 SUCCESS_MULTI_STATUS = 207 REDIRECTION_MULTIPLE_CHOICES = 300 REDIRECTION_MOVED_PERMANENTLY = 301 REDIRECTION_MOVED_TEMPORARILY = 302 REDIRECTION_SEE_OTHER = 303 REDIRECTION_NOT_MODIFIED = 304 REDIRECTION_USE_PROXY = 305 REDIRECTION_TEMPORARY_REDIRECT = 307 CLIENT_ERROR_BAD_REQUEST = 400 CLIENT_ERROR_UNAUTHORIZED = 401 CLIENT_ERROR_PAYMENT_REQUIRED = 402 CLIENT_ERROR_FORBIDDEN = 403 CLIENT_ERROR_NOT_FOUND = 404 CLIENT_ERROR_METHOD_NOT_ALLOWED = 405 CLIENT_ERROR_NOT_ACCEPTABLE = 406 CLIENT_ERROR_PROXY_AUTHENTIFICATION_REQUIRED = 407 CLIENT_ERROR_REQUEST_TIMEOUT = 408 CLIENT_ERROR_CONFLICT = 409 CLIENT_ERROR_GONE = 410 CLIENT_ERROR_LENGTH_REQUIRED = 411 CLIENT_ERROR_PRECONDITION_FAILED = 412 CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE = 413 CLIENT_ERROR_REQUEST_URI_TOO_LONG = 414 CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE = 415 CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE = 416 CLIENT_ERROR_EXPECTATION_FAILED = 417 CLIENT_ERROR_UNPROCESSABLE_ENTITY = 422 CLIENT_ERROR_LOCKED = 423 CLIENT_ERROR_FAILED_DEPENDENCY = 424 SERVER_ERROR_INTERNAL = 500 SERVER_ERROR_NOT_IMPLEMENTED = 501 SERVER_ERROR_BAD_GATEWAY = 502 SERVER_ERROR_SERVICE_UNAVAILABLE = 503 SERVER_ERROR_GATEWAY_TIMEOUT = 504 SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED = 505 SERVER_ERROR_INSUFFICIENT_STORAGE = 507 )
Variables ¶
This section is empty.
Functions ¶
func WithHeader ¶
WithHeader applies the header to the request.
Types ¶
type Body ¶
type Body struct { io.ReadCloser // contains filtered or unexported fields }
func (*Body) JSON ¶
JSON decodes the next JSON encoded object in the body to v.
Example ¶
package main import ( "fmt" "log" "github.com/pkg/requests" ) func main() { var c requests.Client resp, err := c.Get("https://frinkiac.com/api/search?q=burn+that+seat") if err != nil { log.Fatal(err) } defer resp.Close() if !resp.IsSuccess() { log.Fatalf("%s: expected 200, got %v", resp.Request.URL, resp.Status) } var results []struct { Id int `json:"Id"` Episode string `json:"Episode"` Timestamp int `json:"Timestamp"` } err = resp.JSON(&results) fmt.Printf("%#v\n%v", results, err) }
Output:
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a HTTP Client.
func (*Client) Get ¶
Get issues a GET to the specified URL.
Example ¶
package main import ( "fmt" "log" "github.com/pkg/requests" ) func main() { var c requests.Client resp, err := c.Get("https://www.example.com") if err != nil { log.Fatal(err) } fmt.Println(resp.Request.Method, resp.Request.URL, resp.Status.Code) }
Output:
func (*Client) Post ¶
func (c *Client) Post(url string, body io.Reader, options ...func(*Request) error) (*Response, error)
Post issues a POST request to the specified URL.
Example ¶
package main import ( "fmt" "log" "strings" "github.com/pkg/requests" ) func main() { var c requests.Client body := strings.NewReader("Hello there!") resp, err := c.Post("https://www.example.com", body, requests.WithHeader("Content-Type", "application/x-www-form-urlencoded")) if err != nil { log.Fatal(err) } fmt.Println(resp.Request.Method, resp.Request.URL, resp.Status.Code) }
Output:
type Response ¶
Response is a HTTP response.
func (*Response) Header ¶
Header returns the canonicalised version of a response header as a string If there is no key present in the response the empty string is returned. If multiple headers are present, they are canonicalised into as single string by joining them with a comma. See RFC 2616 § 4.2.
Example ¶
package main import ( "fmt" "github.com/pkg/requests" ) var response = requests.Response{ Headers: []requests.Header{ {Key: "Server", Values: []string{"nginx/1.2.1"}}, {Key: "Connection", Values: []string{"keep-alive"}}, {Key: "Content-Type", Values: []string{"text/html; charset=UTF-8"}}, }, } func main() { fmt.Println(response.Header("Server")) fmt.Println(response.Header("Content-Type")) }
Output: nginx/1.2.1 text/html; charset=UTF-8
type Status ¶
Status is a HTTP reponse status.
func (Status) IsClientError ¶
func (Status) IsInformational ¶
func (Status) IsRedirect ¶
func (Status) IsServerError ¶
Click to show internal directories.
Click to hide internal directories.