jsc

package
v0.0.0-...-42497ca Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2016 License: MIT Imports: 11 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, resourceType, id, action string, payload jsh.Sendable) (*jsh.Document, *http.Response, error)

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

func ActionRequest

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

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

func Delete

func Delete(baseURL, resourceType, 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 DeleteMany

func DeleteMany(baseURL, resourceType, id, relationship string, list jsh.IDList) (*jsh.Document, *http.Response, error)

DeleteMany allows a consumer to perform a DELETE /resources/:id/relationships/relationship request.

func DeleteManyRequest

func DeleteManyRequest(baseURL, resourceType, id, relationship string, list jsh.IDList) (*http.Request, error)

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

func DeleteRequest

func DeleteRequest(baseURL, resourceType, 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 /resources/:id request

func FetchRelated

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

FetchRelated performs an outbound GET /resources/:id/relationship request

func FetchRelatedRequest

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

FetchRelatedRequest returns a fully formatted JSONAPI Fetch request for a to-one relationship resource. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.FetchRelated".

func FetchRelationship

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

FetchRelationship performs an outbound GET /resources/:id/relationships/relationship request

func FetchRelationshipRequest

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

FetchRelationshipRequest returns a fully formatted JSONAPI Fetch request for a to-one relationship. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.FetchRelationship".

func FetchRequest

func FetchRequest(baseURL, 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, resourceType string) (*jsh.Document, *http.Response, error)

List performs an outbound GET /resourceTypes request

func ListRelated

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

ListRelated performs an outbound GET /resources/:id/relationship request

func ListRelationship

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

ListRelationship performs an outbound GET /resources/:id/relationships/relationship request

func ListRequest

func ListRequest(baseURL, 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, 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 PatchMany

func PatchMany(baseURL, resourceType, id, relationship string, list jsh.IDList) (*jsh.Document, *http.Response, error)

PatchMany allows a consumer to perform a PATCH /resources/:id/relationships/relationship to-many request.

func PatchManyRequest

func PatchManyRequest(baseURL, resourceType, id, relationship string, list jsh.IDList) (*http.Request, error)

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

func PatchOne

func PatchOne(baseURL, resourceType, id, relationship string, object *jsh.IDObject) (*jsh.Document, *http.Response, error)

PatchOne allows a consumer to perform a PATCH /resources/:id/relationships/relationship to-one request.

func PatchOneRequest

func PatchOneRequest(baseURL, resourceType, id, relationship string, object *jsh.IDObject) (*http.Request, error)

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

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 PostMany

func PostMany(baseURL, resourceType, id, relationship string, list jsh.IDList) (*jsh.Document, *http.Response, error)

PostMany allows a consumer to perform a POST /resources/:id/relationships/relationship request.

func PostManyRequest

func PostManyRequest(baseURL, resourceType, id, relationship string, list jsh.IDList) (*http.Request, error)

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

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".

func TopLevelAction

func TopLevelAction(baseURL, action string, payload jsh.Sendable) (*jsh.Document, *http.Response, error)

TopLevelAction performs an outbound POST /action request

func TopLevelActionRequest

func TopLevelActionRequest(baseURL, action string, payload jsh.Sendable) (*http.Request, error)

TopLevelActionRequest returns a fully formatted JSONAPI Action (POST /action) request. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.TopLevelAction".

Types

This section is empty.

Jump to

Keyboard shortcuts

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