jsc

package
v0.0.0-...-76701a9 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 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 Action

func Action(baseURL string, resourceType string, id string, action string) (*jsh.Document, *http.Response, error)

Action performs an outbound GET /resource/:id/action request

func ActionRequest

func ActionRequest(baseURL string, resourceType, id string, action string) (*http.Request, error)

ActionRequest returns a fully formatted JSONAPI Action (GET /resource/:id/action) request. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.Action".

func Delete

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

Delete allows a user to make an outbound "DELETE /resource/:id" request.

resp, err := jsh.Delete("http://apiserver", "user", "2")

func DeleteRequest

func DeleteRequest(urlStr string, resourceType string, id string) (*http.Request, error)

DeleteRequest returns a fully formatted request for performing a JSON API DELETE. This is useful for if you need to set custom headers on the request. Otherwise just use "jsc.Delete".

func Do

func Do(request *http.Request, mode jsh.DocumentMode) (*jsh.Document, *http.Response, error)

Do sends a the specified request to a JSON API compatible endpoint and returns the resulting JSON Document if possible along with the response, and any errors that were encountered while sending, or parsing the JSON Document.

Useful in conjunction with any of the method Request builders or for times when you want to send a request to a custom endpoint, but would still like a JSONAPI response.

func Document

func Document(response *http.Response, mode jsh.DocumentMode) (*jsh.Document, *jsh.Error)

Document validates the HTTP response and attempts to parse a JSON API compatible Document from the response body before closing it.

func DumpBody

func DumpBody(response *http.Response) (string, *jsh.Error)

DumpBody is a convenience function that parses the body of the response into a string BUT DOESN'T close the ReadCloser. Useful for debugging.

func Fetch

func Fetch(baseURL string, resourceType string, id string) (*jsh.Document, *http.Response, error)

Fetch performs an outbound GET /resourceTypes/:id request

func FetchRequest

func FetchRequest(baseURL string, resourceType, id string) (*http.Request, error)

FetchRequest returns a fully formatted JSONAPI Fetch request. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.Fetch".

func List

func List(baseURL string, resourceType string) (*jsh.Document, *http.Response, error)

List prepares an outbound GET /resourceTypes request

func ListRequest

func ListRequest(baseURL string, resourceType string) (*http.Request, error)

ListRequest returns a fully formatted JSONAPI List request. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.List".

func NewRequest

func NewRequest(method string, urlStr string, body io.Reader) (*http.Request, error)

NewRequest builds a basic request object with the necessary configurations to achieve JSON API compatibility

func ParseResponse

func ParseResponse(response *http.Response, mode jsh.DocumentMode) (*jsh.Document, error)

ParseResponse handles parsing an HTTP response into a JSON Document if possible.

func Patch

func Patch(baseURL string, object *jsh.Object) (*jsh.Document, *http.Response, error)

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

 obj, _ := jsh.NewObject("123", "user", payload)
	// does PATCH /http://postap.com/api/user/123
 json, resp, err := jsc.Patch("http://postap.com/api/", obj)
	updatedObj := json.First()

func PatchRequest

func PatchRequest(baseURL string, object *jsh.Object) (*http.Request, error)

PatchRequest returns a fully formatted request with JSON body for performing a JSONAPI PATCH. This is useful for if you need to set custom headers on the request. Otherwise just use "jsc.Patch".

func Post

func Post(baseURL string, object *jsh.Object) (*jsh.Document, *http.Response, error)

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

obj, _ := jsh.NewObject("123", "user", payload)
// does POST http://apiserver/user/123
json, resp, err := jsh.Post("http://apiserver", obj)

func PostRequest

func PostRequest(baseURL string, object *jsh.Object) (*http.Request, error)

PostRequest returns a fully formatted request with JSON body for performing a JSONAPI POST. This is useful for if you need to set custom headers on the request. Otherwise just use "jsc.Post".

Types

This section is empty.

Jump to

Keyboard shortcuts

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