Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RESTErrorStringLimit = 250
Functions ¶
This section is empty.
Types ¶
type ClientOpt ¶ added in v0.40.0
type ClientOpt func(RestClient)
func AddHeader ¶ added in v0.40.0
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
ReqOpt optionally amends or enhances a request before it is sent.
type Response ¶ added in v0.40.0
type Response struct {
// StatusCode the HTTP status code
StatusCode int
// Header the response headers
Header http.Header
// 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) UnmarshalJSONResponse ¶ added in v0.40.0
Click to show internal directories.
Click to hide internal directories.