rest

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RESTErrorStringLimit = 250

Functions

This section is empty.

Types

type Body

type Body interface {
	Bytes() []byte
	fmt.Stringer
	io.Reader
}

type ClientOpt added in v0.40.0

type ClientOpt func(RestClient)

func AddHeader added in v0.40.0

func AddHeader(key, value string) ClientOpt

AddHeader sets a request header that will be applied to all subsequent requests.

func SetAuthentication added in v0.40.0

func SetAuthentication(authenticator authpkg.Authenticator) ClientOpt

SetAuthentication sets the authentication credentials and method. Leave the authenticator method blank to allow HTTP challenges to select an appropriate method. Otherwise it should be "basic".

func SetHttpClient added in v0.40.0

func SetHttpClient(httpClient httpclient.HttpClient) ClientOpt

SetHttpClient changes the http.Client. This allows control over the http.Transport, timeouts etc.

type ReqOpt added in v0.40.0

type ReqOpt func(*http.Request)

ReqOpt optionally amends or enhances a request before it is sent.

func Headers

func Headers(kv ...string) ReqOpt

Headers adds header values to the request. kv is a list of key & value pairs.

func Query added in v0.40.0

func Query(query urlpkg.Values) ReqOpt

Query sets the query parameters on the request. Existing query parameters are replaced.

func QueryKV added in v0.40.0

func QueryKV(kv ...string) ReqOpt

QueryKV adds query values to the request. kv is a list of key & value pairs.

type Response added in v0.40.0

type Response struct {
	// StatusCode the HTTP status code
	StatusCode int
	// Header the response headers
	Header http.Header
	// Type the content type of the response entity
	Type header.ContentType
	// Body the buffered response entity
	Body *bodypkg.Body
	// Request the original request
	Request *http.Request
}

Response holds an HTTP response with the entity in a buffer.

type RestClient added in v0.40.0

type RestClient interface {
	Request(ctx context.Context, method, path string, reqBody any, opts ...ReqOpt) (*http.Response, error)
	Head(ctx context.Context, path string, opts ...ReqOpt) (*Response, error)
	Get(ctx context.Context, path string, opts ...ReqOpt) (*Response, error)
	Put(ctx context.Context, path string, reqBody any, opts ...ReqOpt) (*Response, error)
	Post(ctx context.Context, path string, reqBody any, opts ...ReqOpt) (*Response, error)
	Delete(ctx context.Context, path string, reqBody any, opts ...ReqOpt) (*Response, error)
	ClearCookies()
}

func NewClient added in v0.40.0

func NewClient(uri string, opts ...ClientOpt) RestClient

NewClient creates a new Client. By default, this uses the default HTTP client.

type RestError added in v0.40.0

type RestError struct {
	Cause        error
	Code         int
	Request      *http.Request
	ResponseType header.ContentType
	Response     Body
}

func (*RestError) Error added in v0.40.0

func (re *RestError) Error() string

Error makes it compatible with `error` interface.

func (*RestError) UnmarshalJSONResponse added in v0.40.0

func (re *RestError) UnmarshalJSONResponse(value any) error

func (*RestError) Unwrap added in v0.40.0

func (re *RestError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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