go-json-spec-handler: github.com/derekdowling/go-json-spec-handler/client Index | Files

package jsc

import "github.com/derekdowling/go-json-spec-handler/client"

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

Index

Package Files

action.go client.go delete.go get.go jsc.go patch.go post.go test_util.go

func Action Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

Fetch performs an outbound GET /resourceTypes/:id request

func FetchRequest Uses

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 Uses

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

List prepares an outbound GET /resourceTypes request

func ListRequest Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

Package jsc imports 10 packages (graph). Updated 2017-07-10. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).