rest

package
v0.0.0-...-bb75d80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package rest implements a simple REST wrapper

All methods are safe for concurrent calling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(resp *http.Response, result interface{}) (err error)

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 NewClient

func NewClient(c *http.Client) *Client

NewClient takes an oauth http.Client and makes a new api instance

func (*Client) Call

func (api *Client) Call(opts *Opts) (resp *http.Response, err error)

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

func (api *Client) SetErrorHandler(fn func(resp *http.Response) error) *Client

SetErrorHandler sets the handler to decode an error response when the HTTP status code is not 2xx. The handler should close resp.Body.

func (*Client) SetHeader

func (api *Client) SetHeader(key, value string) *Client

SetHeader sets a header for all requests

func (*Client) SetRoot

func (api *Client) SetRoot(RootURL string) *Client

SetRoot sets the default root URL

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL