Documentation ¶
Overview ¶
Package gorilla/http is a high level HTTP client.
This package provides high level convience methods for common http operations. Additionally a high level HTTP client implementation.
These high level functions are expected to change. Your feedback on their form and utility is warmly requested.
Please raise issues at https://github.com/gorilla/http/issues.
For lower level http implementations, see gorilla/http/client.
Index ¶
- Variables
- func Get(w io.Writer, url string) (int64, error)
- func Post(url string, r io.Reader) error
- type Client
- func (c *Client) Delete(url string, headers map[string][]string) (client.Status, map[string][]string, io.ReadCloser, error)
- func (c *Client) Do(method, url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
- func (c *Client) Get(url string, headers map[string][]string) (client.Status, map[string][]string, io.ReadCloser, error)
- func (c *Client) Patch(url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
- func (c *Client) Post(url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
- func (c *Client) Put(url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
- type Conn
- type Dialer
- type StatusError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = Client{ FollowRedirects: true, // contains filtered or unexported fields }
DefaultClient is the default http Client used by this package. It's defaults are expected to represent the best practice at the time, but may change over time. If you need more control or reproducibility, you should construct your own client.
Functions ¶
func Get ¶
Get issues a GET request using the DefaultClient and writes the result to to w if successful. If the status code of the response is not a success (see Success.IsSuccess()) no data will be written and the status code will be returned as an error.
Example ¶
// curl in 3 lines of code. if _, err := Get(os.Stdout, "http://www.gorillatoolkit.org/"); err != nil { log.Fatalf("could not fetch: %v", err) }
Output:
func Post ¶
Post issues a POST request using the DefaultClient using r as the body. If the status code was not a success code, it will be returned as an error.
Example ¶
// send the contents of os.Stdin to a remote webserver. if err := Post("http://www.example.com", os.Stdin); err != nil { log.Fatalf("could not post: %v", err) }
Output:
Types ¶
type Client ¶
type Client struct { // FollowRedirects instructs the client to follow 301/302 redirects when idempotent. FollowRedirects bool // contains filtered or unexported fields }
Client implements a high level HTTP client. Client methods can be called concurrently to as many end points as required.
func (*Client) Delete ¶
func (c *Client) Delete(url string, headers map[string][]string) (client.Status, map[string][]string, io.ReadCloser, error)
Delete sends a DELETE request. If the response body is non nil it must be closed.
func (*Client) Do ¶
func (c *Client) Do(method, url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
Do sends an HTTP request and returns an HTTP response. If the response body is non nil it must be closed.
func (*Client) Get ¶
func (c *Client) Get(url string, headers map[string][]string) (client.Status, map[string][]string, io.ReadCloser, error)
Get sends a GET request. If the response body is non nil it must be closed.
func (*Client) Patch ¶
func (c *Client) Patch(url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
Patch sends a PATCH request, suppling the contents of the reader as the request body.
func (*Client) Post ¶
func (c *Client) Post(url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)
Post sends a POST request, suppling the contents of the reader as the request body.
Example ¶
// send the contents of os.Stdin to a remote webserver. status, _, r, err := DefaultClient.Post("http://www.example.com", nil, os.Stdin) if err != nil { log.Fatal(err) } if r != nil { defer r.Close() } log.Printf("Post result: %v", status)
Output:
type Conn ¶
type Conn interface { client.Client io.Closer SetDeadline(time.Time) error SetReadDeadline(time.Time) error SetWriteDeadline(time.Time) error // Release returns the Conn to the Dialer for reuse. Release() }
Conn represnts a connection which can be used to communicate with a remote HTTP server.
type Dialer ¶
type Dialer interface { // Dial dials a remote http server returning a Conn. Dial(network, addr string) (Conn, error) }
Dialer can dial a remote HTTP server.
type StatusError ¶
StatusError reprents a client.Status as an error.
func (*StatusError) Error ¶
func (s *StatusError) Error() string