jsc

package
v0.0.0-...-1f7a8b1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package jsc (JSON Specification Client) is an http client that makes sending HTTP requests that match the JSON Specification: http://jsonapi.org/ simple.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(urlStr string, resourceType string, id string) (*http.Response, error)

Delete allows a user to make an outbound DELETE /resources/:id request:

resp, err := jsh.Get("http://apiserver", "user", "2")
obj := resp.GetObject()

Types

type Response

type Response struct {
	*http.Response
}

Response is a wrapper around an http.Response that allows us to perform intelligent actions on them

func Get

func Get(urlStr string, resourceType string, id string) (*Response, error)

Get allows a user to make an outbound GET /resources(/:id) request.

For a GET request that retrieves multiple resources, pass an empty string for the id parameter:

 GET "http://apiserver/users
	resp, err := jsh.Get("http://apiserver", "user", "")
	list, err := resp.GetList()

For a GET request on a specific attribute:

 GET "http://apiserver/users/2
	resp, err := jsh.Get("http://apiserver", "user", "2")
	obj := resp.GetObject()

func Patch

func Patch(urlStr string, object *jsh.Object) (*Response, error)

Patch allows a consumer to perform a PATCH /resources/:id request Example:

obj, _ := jsh.NewObject("123", "resource_name", payload)
resp, _ := jsc.Patch("http://postap.com", obj)
updatedObj, _ := resp.GetObject()

func Post

func Post(urlStr string, object *jsh.Object) (*Response, error)

Post allows a user to make an outbound POST /resources request:

resp, err := jsh.Get("http://apiserver", "user", "2")
obj := resp.GetObject()

func (*Response) BodyStr

func (r *Response) BodyStr() (string, error)

BodyStr is a convenience function that parses the body of the response into a string BUT DOESN'T close the ReadCloser

func (*Response) GetList

func (r *Response) GetList() (jsh.List, error)

GetList validates the http response and parses out the JSON list from the body if possible

func (*Response) GetObject

func (r *Response) GetObject() (*jsh.Object, error)

GetObject validates the http response and parses out the JSON object from the body if possible

Jump to

Keyboard shortcuts

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