Documentation
¶
Index ¶
- Variables
- func DefaultClient(timeout time.Duration) httpclient.HttpClient
- func Headers(headerKeyVals ...string) http.Header
- func RESTClient(timeout time.Duration) httpclient.HttpClient
- func SetDefaultTLSConfig(cfg *tls.Config)
- type Body
- type HttpClient
- type RESTError
- type RESTRequest
- func (rr *RESTRequest) Delete(httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) Get(httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) HTTPRoundTrip(method string, httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) Head(httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) Patch(httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) Post(httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) Put(httpClient HttpClient) *RESTResponse
- func (rr *RESTRequest) Query(query urlpkg.Values) *RESTRequest
- func (rr *RESTRequest) With(m http.Header) *RESTRequest
- func (rr *RESTRequest) WithKV(headerKeyVals ...string) *RESTRequest
- type RESTResponse
Constants ¶
This section is empty.
Variables ¶
var DefaultTransport http.RoundTripper
var RESTErrorStringLimit = 250
Functions ¶
func DefaultClient ¶
func DefaultClient(timeout time.Duration) httpclient.HttpClient
DefaultClient gets a http.Client with the DefaultTransport as its round-tripper and a specified timeout. A timeout of zero means no timeout.
func RESTClient ¶
func RESTClient(timeout time.Duration) httpclient.HttpClient
RESTClient returns a client that sets request headers on every request.
- Host: (from URL)
- Accept: application/json
func SetDefaultTLSConfig ¶
SetDefaultTLSConfig sets the TLS configuration used by the default transport.
Types ¶
type RESTError ¶
type RESTError struct {
Code int
Request *http.Request
ResponseType header.ContentType
Response Body
// contains filtered or unexported fields
}
func (*RESTError) UnmarshalJSONResponse ¶
type RESTRequest ¶
type RESTRequest struct {
// contains filtered or unexported fields
}
func JSON ¶
func JSON(ctx context.Context, url string, input any) *RESTRequest
JSON constructs a request using a URL. The request will have a JSON entity.
func Request ¶
func Request(ctx context.Context, url string) *RESTRequest
Request constructs a request using a URL. The request will not have an entity.
func (*RESTRequest) Delete ¶
func (rr *RESTRequest) Delete(httpClient HttpClient) *RESTResponse
Delete performs an HTTP DELETE request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) Get ¶
func (rr *RESTRequest) Get(httpClient HttpClient) *RESTResponse
Get performs an HTTP GET request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) HTTPRoundTrip ¶
func (rr *RESTRequest) HTTPRoundTrip(method string, httpClient HttpClient) *RESTResponse
HTTPRoundTrip performs an arbitrary HTTP request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) Head ¶
func (rr *RESTRequest) Head(httpClient HttpClient) *RESTResponse
Head performs an HTTP HEAD request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) Patch ¶
func (rr *RESTRequest) Patch(httpClient HttpClient) *RESTResponse
Patch performs an HTTP PATCH request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) Post ¶
func (rr *RESTRequest) Post(httpClient HttpClient) *RESTResponse
Post performs an HTTP POST request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) Put ¶
func (rr *RESTRequest) Put(httpClient HttpClient) *RESTResponse
Put performs an HTTP PUT request. The response headers and status code are returned. In order to close resources correctly, it is essential to call one of RESTResponse.Status, RESTResponse.Unmarshal or RESTResponse.ToMap
func (*RESTRequest) Query ¶
func (rr *RESTRequest) Query(query urlpkg.Values) *RESTRequest
Query adds query parameters to the request, as if a "?key=value" list had been attached to the URL.
func (*RESTRequest) With ¶
func (rr *RESTRequest) With(m http.Header) *RESTRequest
With adds headers to the request.
func (*RESTRequest) WithKV ¶
func (rr *RESTRequest) WithKV(headerKeyVals ...string) *RESTRequest
WithKV adds key-value pairs as headers to the request.
type RESTResponse ¶
func (*RESTResponse) Status ¶
func (rr *RESTResponse) Status() (respHeader http.Header, statusCode int, err error)
Status gets the status of the response.
func (*RESTResponse) ToMap ¶
func (rr *RESTResponse) ToMap() (data map[string]any, statusCode int, err error)
ToMap extracts a map containing a tree of data from the JSON response. If the response does not contain JSON, the map will be nil.
func (*RESTResponse) Unmarshal ¶
Unmarshal extracts data from the response. Typically, when the response contains JSON, output will be a pointer to a struct that matches the expected content. However, it may also be *string or *[]byte. See RESTResponse.ToMap.