Documentation ¶
Overview ¶
Package rest implements a simple REST wrapper
Index ¶
- func DecodeJSON(resp *http.Response, result interface{}) (err error)
- type Client
- func (api *Client) Call(opts *Opts) (resp *http.Response, err error)
- func (api *Client) CallJSON(opts *Opts, request interface{}, response interface{}) (resp *http.Response, err error)
- func (api *Client) SetErrorHandler(fn func(resp *http.Response) error) *Client
- func (api *Client) SetHeader(key, value string) *Client
- func (api *Client) SetRoot(RootURL string) *Client
- type Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes resp.Body into result
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client contains the info to sustain the API
func (*Client) Call ¶
Call makes the call and returns the http.Response
if err != nil then resp.Body will need to be closed
it will return resp if at all possible, even if err is set
func (*Client) CallJSON ¶
func (api *Client) CallJSON(opts *Opts, request interface{}, response interface{}) (resp *http.Response, err error)
CallJSON runs Call and decodes the body as a JSON object into response (if not nil)
If request is not nil then it will be JSON encoded as the body of the request ¶
It will return resp if at all possible, even if err is set
func (*Client) SetErrorHandler ¶
SetErrorHandler sets the handler to decode an error response when the HTTP status code is not 2xx. The handler should close resp.Body.
type Opts ¶
type Opts struct { Method string Path string Absolute bool // Path is absolute Body io.Reader NoResponse bool // set to close Body ContentType string ContentLength *int64 ContentRange string ExtraHeaders map[string]string UserName string // username for Basic Auth Password string // password for Basic Auth }
Opts contains parameters for Call, CallJSON etc
Click to show internal directories.
Click to hide internal directories.