Documentation ¶
Overview ¶
Package httputil implements a wrapper around the standard library's HTTP client.
Index ¶
- func WithBody(r io.Reader) func(*http.Request) error
- func WithExactHeader(key string, values ...string) func(*http.Request) error
- func WithHeader(header http.Header) func(*http.Request) error
- func WithJSONBody(v interface{}) func(*http.Request) error
- func WithURLValues(values url.Values) func(*http.Request) error
- type Client
- type RequestOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithExactHeader ¶
WithExactHeader adds the exact given header to the request, replacing an existing one with the same name, if it exists.
func WithHeader ¶
WithHeader adds headers to the request.
func WithJSONBody ¶
WithJSONBody adds a JSON body to the request.
Types ¶
type Client ¶
type Client struct { Client *http.Client // optional: if set, this is added to any requests as the "User-Agent" header. UserAgent string // optional: if set, this is added to any requests as the "Authorization" header. Token string // contains filtered or unexported fields }
Client is a http client with convenience methods for making requests.
func WrapClient ¶
WrapClient wraps an existing *http.Client.
func (*Client) AddOptions ¶
func (c *Client) AddOptions(opts ...RequestOption)
AddOptions adds the given RequestOptions to the
func (*Client) Request ¶
func (c *Client) Request(method, url string, opts ...RequestOption) (resp *http.Response, err error)
Request makes a request. It is the caller's responsibility to close the response body.
func (*Client) RequestJSON ¶
func (c *Client) RequestJSON(out interface{}, method, url string, opts ...RequestOption) (code int, err error)
RequestJSON makes a request returning a JSON body.
type RequestOption ¶
RequestOption is an optional request option.
Click to show internal directories.
Click to hide internal directories.