httpx

package
v3.12.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package httpx contains http extensions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Accept contains the accept header.
	Accept string

	// Authorization contains the authorization header.
	Authorization string

	// BaseURL is the base URL of the API.
	BaseURL string

	// HTTPClient is the real http client to use.
	HTTPClient *http.Client

	// Host allows to set a specific host header. This is useful
	// to implement, e.g., cloudfronting.
	Host string

	// Logger is the logger to use.
	Logger Logger

	// UserAgent is the user agent to use.
	UserAgent string
}

Client is an extended client.

func (Client) Do

func (c Client) Do(request *http.Request) ([]byte, error)

Do performs the provided request and returns the response body or an error.

func (Client) DoJSON

func (c Client) DoJSON(request *http.Request, output interface{}) error

DoJSON performs the provided request and unmarshals the JSON response body into the provided output variable.

func (Client) FetchResource

func (c Client) FetchResource(ctx context.Context, URLPath string) ([]byte, error)

FetchResource fetches the specified resource and returns it.

func (Client) FetchResourceAndVerify

func (c Client) FetchResourceAndVerify(ctx context.Context, URL, SHA256Sum string) ([]byte, error)

FetchResourceAndVerify fetches and verifies a specific resource.

func (Client) GetJSON

func (c Client) GetJSON(ctx context.Context, resourcePath string, output interface{}) error

GetJSON reads the JSON resource at resourcePath and unmarshals the results into output. The request is bounded by the lifetime of the context passed as argument. Returns the error that occurred.

func (Client) GetJSONWithQuery

func (c Client) GetJSONWithQuery(
	ctx context.Context, resourcePath string,
	query url.Values, output interface{}) error

GetJSONWithQuery is like GetJSON but also has a query.

func (Client) NewRequest

func (c Client) NewRequest(ctx context.Context, method, resourcePath string,
	query url.Values, body io.Reader) (*http.Request, error)

NewRequest creates a new request.

func (Client) NewRequestWithJSONBody

func (c Client) NewRequestWithJSONBody(
	ctx context.Context, method, resourcePath string,
	query url.Values, body interface{}) (*http.Request, error)

NewRequestWithJSONBody creates a new request with a JSON body

func (Client) PostJSON

func (c Client) PostJSON(
	ctx context.Context, resourcePath string, input, output interface{}) error

PostJSON creates a JSON subresource of the resource at resourcePath using the JSON document at input and returning the result into the JSON document at output. The request is bounded by the context's lifetime. Returns the error that occurred.

func (Client) PutJSON

func (c Client) PutJSON(
	ctx context.Context, resourcePath string, input, output interface{}) error

PutJSON updates a JSON resource at a specific path and returns the error that occurred and possibly an output document

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
}

Logger is the definition of Logger used by this package.

Jump to

Keyboard shortcuts

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