package http

import "github.com/gorilla/http"

Installation | Overview | API | Files | Subdirectories

Installation

$ go get github.com/gorilla/http

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.

API

Package Files

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

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.

Example

func Post

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.

Example

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

func (*Client) Put

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

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

type StatusError struct {
    client.Status
}

StatusError reprents a client.Status as an error.

func (*StatusError) Error

func (s *StatusError) Error() string

Subdirectories

Packages

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