gocrayons

package module
v0.0.0-...-ee59c27 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2014 License: Apache-2.0 Imports: 10 Imported by: 2

README

gocrayons - REST api consumer with simplejson

GoDoc Build Status

Summary

gocrayons is a fork of bndr/gopencils. The main change is the use of github.com/bitly/go-simplejson for JSON handling.

Install

go get github.com/cryptix/gocrayons

Usage example

Please see the examples directory.

Why?

simplejson makes it easier to work with strange and irregular json that can't be simple handled by encoding/json's Unmarshal()

Is it ready?

It is more beta than bndrs original.

Contribute

All Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.

License

Apache License 2.0

TODO

  1. Add examples

Documentation

Overview

Package gocrayons is a Golang REST Client with which you can easily consume REST API's. Uses bily/simplejson

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type ApiStruct

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

type BasicAuth struct {
	Username string
	Password string
}

Basic Auth

type Resource

type Resource struct {
	Api *ApiStruct
	Url string

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

Resource is basically an url relative to given API Baseurl.

func Api

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

func (r *Resource) Delete(params map[string]string) (*Resource, error)

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

func (*Resource) FormPost

func (r *Resource) FormPost(params map[string]string) (*Resource, error)

FormPost doesn't touch the payload

func (*Resource) Get

func (r *Resource) Get(params map[string]string) (*Resource, error)

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

func (*Resource) Head

func (r *Resource) Head(params map[string]string) (*Resource, error)

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

func (*Resource) Id

func (r *Resource) Id(id interface{}) *Resource

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

func (*Resource) Options

func (r *Resource) Options(params map[string]string) (*Resource, error)

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

func (*Resource) Patch

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

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

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

func (r *Resource) Res(path string) *Resource

Creates a new Resource.

func (*Resource) SetClient

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

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

Sets Headers

func (*Resource) SetPayload

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

Sets Payload for current Resource

func (*Resource) SetQuery

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

Notes

Bugs

  • don't panic..

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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