http: github.com/gorilla/http Index | Examples | Files | Directories

package http

import "github.com/gorilla/http"

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

Examples

Package Files

client.go conn.go http.go

Variables

var DefaultClient = Client{
    dialer:          new(dialer),
    FollowRedirects: true,
}

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.

func Get Uses

func Get(w io.Writer, url string) (int64, error)

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.

Code:

// curl in 3 lines of code.
if _, err := Get(os.Stdout, "http://www.gorillatoolkit.org/"); err != nil {
    log.Fatalf("could not fetch: %v", err)
}

func Post Uses

func Post(url string, r io.Reader) error

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.

Code:

// 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)
}

type Client Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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.

Code:

// 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)

func (*Client) Put Uses

func (c *Client) Put(url string, headers map[string][]string, body io.Reader) (client.Status, map[string][]string, io.ReadCloser, error)

Put sends a PUT request, suppling the contents of the reader as the request body.

type Conn Uses

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 Uses

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 Uses

type StatusError struct {
    client.Status
}

StatusError reprents a client.Status as an error.

func (*StatusError) Error Uses

func (s *StatusError) Error() string

Directories

PathSynopsis
clientPackage gorilla/http/client contains the lower level HTTP client implementation.

Package http imports 10 packages (graph) and is imported by 12 packages. Updated 2018-05-27. Refresh now. Tools for package owners.