gopencils: github.com/bndr/gopencils Index | Files | Directories

package gopencils

import "github.com/bndr/gopencils"

Gopencils is a Golang REST Client with which you can easily consume REST API's. Supported Response formats: JSON

Index

Package Files

api.go resource.go

Variables

var ErrCantUseAsQuery = errors.New("can't use options[0] as Query")

type ApiStruct Uses

type ApiStruct struct {
    BaseUrl    *url.URL
    BasicAuth  *BasicAuth
    Client     *http.Client
    Cookies    *cookiejar.Jar
    PathSuffix string
}

Main Api Instance. No Options yet supported.

type BasicAuth Uses

type BasicAuth struct {
    Username string
    Password string
}

Basic Auth

type Resource Uses

type Resource struct {
    Api *ApiStruct
    Url string

    QueryValues url.Values
    Payload     io.Reader
    Headers     http.Header
    Response    interface{}
    Raw         *http.Response
    // contains filtered or unexported fields
}

Resource is basically an url relative to given API Baseurl.

func Api Uses

func Api(baseUrl string, options ...interface{}) *Resource

Create a new API Instance and returns a Resource Accepts URL as parameter, and either a Basic Auth or a OAuth2 Client.

func (*Resource) Delete Uses

func (r *Resource) Delete(options ...interface{}) (*Resource, error)

Performs a Delete request on given Resource. Accepts map[string]string as parameter, will be used as querystring.

func (*Resource) Get Uses

func (r *Resource) Get(options ...interface{}) (*Resource, error)

Performs a GET request on given Resource Accepts map[string]string as parameter, will be used as querystring.

func (*Resource) Head Uses

func (r *Resource) Head(options ...interface{}) (*Resource, error)

Performs a HEAD request on given Resource Accepts map[string]string as parameter, will be used as querystring.

func (*Resource) Id Uses

func (r *Resource) Id(options ...interface{}) *Resource

Same as Res() Method, but returns a Resource with url resource/:id

func (*Resource) Options Uses

func (r *Resource) Options(options ...interface{}) (*Resource, error)

Performs a Delete request on given Resource. Accepts map[string]string as parameter, will be used as querystring.

func (*Resource) Patch Uses

func (r *Resource) Patch(options ...interface{}) (*Resource, error)

Performs a PATCH request on given Resource. Accepts interface{} as parameter, will be used as payload.

func (*Resource) Post Uses

func (r *Resource) Post(options ...interface{}) (*Resource, error)

Performs a POST request on given Resource. Accepts interface{} as parameter, will be used as payload.

func (*Resource) Put Uses

func (r *Resource) Put(options ...interface{}) (*Resource, error)

Performs a PUT request on given Resource. Accepts interface{} as parameter, will be used as payload.

func (*Resource) Res Uses

func (r *Resource) Res(options ...interface{}) *Resource

Creates a new Resource.

func (*Resource) SetClient Uses

func (r *Resource) SetClient(c *http.Client)

Overwrites the client that will be used for requests. For example if you want to use your own client with OAuth2

func (*Resource) SetHeader Uses

func (r *Resource) SetHeader(key string, value string)

Sets Headers

func (*Resource) SetPayload Uses

func (r *Resource) SetPayload(args interface{}) io.Reader

Sets Payload for current Resource

func (*Resource) SetQuery Uses

func (r *Resource) SetQuery(querystring map[string]string) *Resource

Sets QueryValues for current Resource

Directories

PathSynopsis
examples

Package gopencils imports 9 packages (graph) and is imported by 16 packages. Updated 2016-11-13. Refresh now. Tools for package owners.