httputil

package
v0.0.0-...-fa60fbe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2021 License: ISC Imports: 6 Imported by: 0

Documentation

Overview

Package httputil implements a wrapper around the standard library's HTTP client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBody

func WithBody(r io.Reader) func(*http.Request) error

WithBody adds a body to the request.

func WithExactHeader

func WithExactHeader(key string, values ...string) func(*http.Request) error

WithExactHeader adds the exact given header to the request, replacing an existing one with the same name, if it exists.

func WithHeader

func WithHeader(header http.Header) func(*http.Request) error

WithHeader adds headers to the request.

func WithJSONBody

func WithJSONBody(v interface{}) func(*http.Request) error

WithJSONBody adds a JSON body to the request.

func WithURLValues

func WithURLValues(values url.Values) func(*http.Request) error

WithURLValues adds query parameters 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 New

func New() *Client

New returns a new Client.

func WrapClient

func WrapClient(c *http.Client) *Client

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

type RequestOption func(*http.Request) error

RequestOption is an optional request option.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL