Documentation
¶
Index ¶
- func Make(ctx context.Context, options *CallOptions) (*http.Response, error)
- type CallOptions
- func (s *CallOptions) AddHeaders(kvs ...string) *CallOptions
- func (s *CallOptions) AddParams(kvs ...string) *CallOptions
- func (s *CallOptions) DELETE(url string) *CallOptions
- func (s *CallOptions) Form(payload interface{}) *CallOptions
- func (s *CallOptions) GET(url string) *CallOptions
- func (s *CallOptions) IsSuccessWhenStatus(statuses ...int) *CallOptions
- func (s *CallOptions) IsSuccessWhenStatusInRange(lowerInclusive int, upperInclusive int) *CallOptions
- func (s *CallOptions) JSON(payload interface{}) *CallOptions
- func (s *CallOptions) PATCH(url string) *CallOptions
- func (s *CallOptions) POST(url string) *CallOptions
- func (s *CallOptions) PUT(url string) *CallOptions
- func (s *CallOptions) Plain(payload interface{}) *CallOptions
- func (s *CallOptions) ToError(codec httpcodec.Decoder) *CallOptions
- func (s *CallOptions) ToFormError(destination *url.Values) *CallOptions
- func (s *CallOptions) ToFormSuccess(destination *url.Values) *CallOptions
- func (s *CallOptions) ToJSONError(destination interface{}) *CallOptions
- func (s *CallOptions) ToJSONSuccess(destination interface{}) *CallOptions
- func (s *CallOptions) ToPlainError(destination io.Writer) *CallOptions
- func (s *CallOptions) ToPlainSuccess(destination io.Writer) *CallOptions
- func (s *CallOptions) ToSuccess(codec httpcodec.Decoder) *CallOptions
- func (s *CallOptions) ToXMLError(destination interface{}) *CallOptions
- func (s *CallOptions) ToXMLSuccess(destination interface{}) *CallOptions
- func (s *CallOptions) WithClient(client *http.Client) *CallOptions
- func (s *CallOptions) WithMethod(method string) *CallOptions
- func (s *CallOptions) WithPayload(payload interface{}, codec httpcodec.Encoder) *CallOptions
- func (s *CallOptions) WithSuccessCriteria(criteria func(resp *http.Response) bool) *CallOptions
- func (s *CallOptions) WithURL(url string) *CallOptions
- func (s *CallOptions) XML(payload interface{}) *CallOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallOptions ¶
type CallOptions struct {
// contains filtered or unexported fields
}
func Options ¶
func Options() *CallOptions
Options returns a new default call context, with the default http.Client; GET as http method; raw encoding for payload; 2XX status code to be considered successful response.
func (*CallOptions) AddHeaders ¶
func (s *CallOptions) AddHeaders(kvs ...string) *CallOptions
AddHeaders adds the key value pairs as headers. If the supplied key values are not in pairs, this method panics.
func (*CallOptions) AddParams ¶
func (s *CallOptions) AddParams(kvs ...string) *CallOptions
AddParams adds the key value pairs as query parameters. If the supplied key values are not in pairs, this method panics.
func (*CallOptions) DELETE ¶
func (s *CallOptions) DELETE(url string) *CallOptions
DELETE is shortcut for WithMethod and WithURL
func (*CallOptions) Form ¶
func (s *CallOptions) Form(payload interface{}) *CallOptions
Form sets the payload and also the "Content-Type" header to "application/x-www-form-urlencoded". If payload is nil, this method is noop. Check github.com/absurdlab/pkg/httpcodec for accepted types.
func (*CallOptions) GET ¶
func (s *CallOptions) GET(url string) *CallOptions
GET is shortcut for WithMethod and WithURL
func (*CallOptions) IsSuccessWhenStatus ¶
func (s *CallOptions) IsSuccessWhenStatus(statuses ...int) *CallOptions
IsSuccessWhenStatus sets the success criteria to that the response is only successful when it returns one of the supplied status code.
func (*CallOptions) IsSuccessWhenStatusInRange ¶
func (s *CallOptions) IsSuccessWhenStatusInRange(lowerInclusive int, upperInclusive int) *CallOptions
IsSuccessWhenStatusInRange sets the success criteria to that the response is only successful when it returns a status code in the supplied range.
func (*CallOptions) JSON ¶
func (s *CallOptions) JSON(payload interface{}) *CallOptions
JSON sets the payload and also the "Content-Type" header to "application/json". If payload is nil, this method is noop.
func (*CallOptions) PATCH ¶
func (s *CallOptions) PATCH(url string) *CallOptions
PATCH is shortcut for WithMethod and WithURL
func (*CallOptions) POST ¶
func (s *CallOptions) POST(url string) *CallOptions
POST is shortcut for WithMethod and WithURL
func (*CallOptions) PUT ¶
func (s *CallOptions) PUT(url string) *CallOptions
PUT is shortcut for WithMethod and WithURL
func (*CallOptions) Plain ¶
func (s *CallOptions) Plain(payload interface{}) *CallOptions
Plain sets the payload and also the "Content-Type" header to "text/plain". If payload is nil, this method is noop. Check github.com/absurdlab/pkg/httpcodec for accepted types.
func (*CallOptions) ToError ¶
func (s *CallOptions) ToError(codec httpcodec.Decoder) *CallOptions
ToError sets error response codec. If codec is nil, this method is noop.
func (*CallOptions) ToFormError ¶
func (s *CallOptions) ToFormError(destination *url.Values) *CallOptions
ToFormError sets error response codec to form decoder and sets "Accept" header to "application/x-www-form-urlencoded". If destination is nil, this method is noop.
func (*CallOptions) ToFormSuccess ¶
func (s *CallOptions) ToFormSuccess(destination *url.Values) *CallOptions
ToFormSuccess sets success response codec to form decoder and sets "Accept" header to "application/x-www-form-urlencoded". If destination is nil, this method is noop.
func (*CallOptions) ToJSONError ¶
func (s *CallOptions) ToJSONError(destination interface{}) *CallOptions
ToJSONError sets error response codec to json decoder and sets "Accept" header to "application/json". If destination is nil, this method is noop.
func (*CallOptions) ToJSONSuccess ¶
func (s *CallOptions) ToJSONSuccess(destination interface{}) *CallOptions
ToJSONSuccess sets success response codec to json decoder and sets "Accept" header to "application/json". If destination is nil, this method is noop.
func (*CallOptions) ToPlainError ¶
func (s *CallOptions) ToPlainError(destination io.Writer) *CallOptions
ToPlainError sets error response codec to form decoder and sets "Accept" header to "text/plain". If destination is nil, this method is noop.
func (*CallOptions) ToPlainSuccess ¶
func (s *CallOptions) ToPlainSuccess(destination io.Writer) *CallOptions
ToPlainSuccess sets success response codec to form decoder and sets "Accept" header to "text/plain". If destination is nil, this method is noop.
func (*CallOptions) ToSuccess ¶
func (s *CallOptions) ToSuccess(codec httpcodec.Decoder) *CallOptions
ToSuccess sets success response codec. If codec is nil, this method is noop.
func (*CallOptions) ToXMLError ¶
func (s *CallOptions) ToXMLError(destination interface{}) *CallOptions
ToXMLError sets error response codec to xml decoder and sets "Accept" header to "application/xml". If destination is nil, this method is noop.
func (*CallOptions) ToXMLSuccess ¶
func (s *CallOptions) ToXMLSuccess(destination interface{}) *CallOptions
ToXMLSuccess sets success response codec to xml decoder and sets "Accept" header to "application/xml". If destination is nil, this method is noop.
func (*CallOptions) WithClient ¶
func (s *CallOptions) WithClient(client *http.Client) *CallOptions
WithClient configures a new http.Client.
func (*CallOptions) WithMethod ¶
func (s *CallOptions) WithMethod(method string) *CallOptions
WithMethod configures a new HTTP method. If invalid HTTP method is supplied, this method is noop.
func (*CallOptions) WithPayload ¶
func (s *CallOptions) WithPayload(payload interface{}, codec httpcodec.Encoder) *CallOptions
WithPayload sets custom payload and encoder. If either is nil, this method is noop.
func (*CallOptions) WithSuccessCriteria ¶
func (s *CallOptions) WithSuccessCriteria(criteria func(resp *http.Response) bool) *CallOptions
WithSuccessCriteria sets the success criteria. If criteria is nil, this method is noop.
func (*CallOptions) WithURL ¶
func (s *CallOptions) WithURL(url string) *CallOptions
WithURL sets the target url. If supplied url is empty, the method is noop.
func (*CallOptions) XML ¶
func (s *CallOptions) XML(payload interface{}) *CallOptions
XML sets the payload and also the "Content-Type" header to "application/xml". If payload is nil, this method is noop.