Documentation ¶
Index ¶
- func WithBaseURL(base string) func(*Helper)
- func WithBasicAuth(username, password string) func(*Helper)
- func WithBody(body io.Reader) func(*Request)
- func WithContentType(ct string) func(*Request)
- func WithHeader(k, v string) func(*Helper)
- func WithJSON(v interface{}) func(*Request)
- func WithParser(mimeType string, fn Parser) func(*Helper)
- func WithQuery(k, v string) func(*Request)
- func WithRequestHeader(k, v string) func(*Request)
- func WithTimeout(d time.Duration) func(*Helper)
- func WithXML(v interface{}) func(*Request)
- type Helper
- func (h *Helper) Delete(path string, opts ...RequestOption) (*Request, error)
- func (h *Helper) Get(path string, opts ...RequestOption) (*Request, error)
- func (h *Helper) NewRequest(method, path string, opts ...RequestOption) (*Request, error)
- func (h *Helper) Patch(path string, opts ...RequestOption) (*Request, error)
- func (h *Helper) Post(path string, opts ...RequestOption) (*Request, error)
- func (h *Helper) Put(path string, opts ...RequestOption) (*Request, error)
- type HelperOption
- type Parser
- type Request
- type RequestOption
- type Response
- func (r *Response) BodyBytes() ([]byte, error)
- func (r *Response) Close()
- func (r *Response) Error() string
- func (r *Response) IsOK() bool
- func (r *Response) Parse(v interface{}) error
- func (r *Response) ParseContentType() string
- func (r *Response) ParseJSON(v interface{}) error
- func (r *Response) ParseXML(v interface{}) error
- func (r *Response) Status() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithBaseURL ¶
WithBaseURL sets the base URL of the Helper object.
func WithBasicAuth ¶ added in v0.2.0
WithBasicAuth sets the Authorization header with the given username and password.
func WithContentType ¶
WithContentType sets the Content-Type header of the request.
func WithHeader ¶
WithHeader sets the default header of the Helper object (like same Authorization header)
func WithJSON ¶
func WithJSON(v interface{}) func(*Request)
WithJSON sets the body of the request using JSON of the supplied value.
func WithParser ¶
WithParser adds a parser to the Helper object for the given MIME type.
func WithRequestHeader ¶
WithRequestHeader adds a header to the request.
func WithTimeout ¶
WithTimeout sets the timeout of http.Client.
Types ¶
type Helper ¶
type Helper struct {
// contains filtered or unexported fields
}
Helper is an object that contains the base URL, headers, and client and help you create requests to an API.
func New ¶
func New(opts ...HelperOption) *Helper
New creates a new Helper object with the given options.
func (*Helper) Delete ¶
func (h *Helper) Delete(path string, opts ...RequestOption) (*Request, error)
Delete creates a DELETE request to the given path
func (*Helper) Get ¶
func (h *Helper) Get(path string, opts ...RequestOption) (*Request, error)
Get creates a GET request to the given path
func (*Helper) NewRequest ¶
func (h *Helper) NewRequest(method, path string, opts ...RequestOption) (*Request, error)
NewRequest creates a new Request object with the given options.
func (*Helper) Patch ¶
func (h *Helper) Patch(path string, opts ...RequestOption) (*Request, error)
Patch creates a PATCH request to the given path
type HelperOption ¶
type HelperOption func(*Helper)
HelperOption is a function that modifies the Helper object.
type Parser ¶
type Parser func(interface{}) error
Parser is a function that parses the response body into an object.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is how you create a request to an API.
type RequestOption ¶
type RequestOption func(*Request)
RequestOption is a function that modifies the Request object.
type Response ¶
Response is the response of a request.
func (*Response) Close ¶
func (r *Response) Close()
Close closes the response body. (should always be called after Do())
func (*Response) Error ¶
Error returns the error message of the response (or the status since it's "now" considered an error)
func (*Response) Parse ¶
Parse parses the response into the supplied value (using the 'Content-Type' header)
func (*Response) ParseContentType ¶
ParseContentType returns the simple content-type of the response.