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 ¶
- func Action(baseURL, resourceType, id, action string, payload jsh.Sendable) (*jsh.Document, *http.Response, error)
- func ActionRequest(baseURL, resourceType, id, action string, payload jsh.Sendable) (*http.Request, error)
- func Delete(baseURL, resourceType, id string) (*http.Response, error)
- func DeleteMany(baseURL, resourceType, id, relationship string, list jsh.IDList) (*jsh.Document, *http.Response, error)
- func DeleteManyRequest(baseURL, resourceType, id, relationship string, list jsh.IDList) (*http.Request, error)
- func DeleteRequest(baseURL, resourceType, id string) (*http.Request, error)
- func Do(request *http.Request, mode jsh.DocumentMode) (*jsh.Document, *http.Response, error)
- func Document(response *http.Response, mode jsh.DocumentMode) (*jsh.Document, *jsh.Error)
- func DumpBody(response *http.Response) (string, *jsh.Error)
- func Fetch(baseURL string, resourceType string, id string) (*jsh.Document, *http.Response, error)
- func FetchRelated(baseURL, resourceType, id, relationship string) (*jsh.Document, *http.Response, error)
- func FetchRelatedRequest(baseURL, resourceType, id, relationship string) (*http.Request, error)
- func FetchRelationship(baseURL, resourceType, id, relationship string) (*jsh.Document, *http.Response, error)
- func FetchRelationshipRequest(baseURL, resourceType, id, relationship string) (*http.Request, error)
- func FetchRequest(baseURL, resourceType, id string) (*http.Request, error)
- func List(baseURL, resourceType string) (*jsh.Document, *http.Response, error)
- func ListRelated(baseURL, resourceType, id, relationship string) (*jsh.Document, *http.Response, error)
- func ListRelationship(baseURL, resourceType, id, relationship string) (*jsh.Document, *http.Response, error)
- func ListRequest(baseURL, resourceType string) (*http.Request, error)
- func NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)
- func ParseResponse(response *http.Response, mode jsh.DocumentMode) (*jsh.Document, error)
- func Patch(baseURL string, object *jsh.Object) (*jsh.Document, *http.Response, error)
- func PatchMany(baseURL, resourceType, id, relationship string, list jsh.IDList) (*jsh.Document, *http.Response, error)
- func PatchManyRequest(baseURL, resourceType, id, relationship string, list jsh.IDList) (*http.Request, error)
- func PatchOne(baseURL, resourceType, id, relationship string, object *jsh.IDObject) (*jsh.Document, *http.Response, error)
- func PatchOneRequest(baseURL, resourceType, id, relationship string, object *jsh.IDObject) (*http.Request, error)
- func PatchRequest(baseURL string, object *jsh.Object) (*http.Request, error)
- func Post(baseURL string, object *jsh.Object) (*jsh.Document, *http.Response, error)
- func PostMany(baseURL, resourceType, id, relationship string, list jsh.IDList) (*jsh.Document, *http.Response, error)
- func PostManyRequest(baseURL, resourceType, id, relationship string, list jsh.IDList) (*http.Request, error)
- func PostRequest(baseURL string, object *jsh.Object) (*http.Request, error)
- func TopLevelAction(baseURL, action string, payload jsh.Sendable) (*jsh.Document, *http.Response, error)
- func TopLevelActionRequest(baseURL, action string, payload jsh.Sendable) (*http.Request, error)
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 ¶
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 ¶
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 ¶
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 ¶
Document validates the HTTP response and attempts to parse a JSON API compatible Document from the response body before closing it.
func DumpBody ¶
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 FetchRelated ¶
func FetchRelated(baseURL, resourceType, id, relationship string) (*jsh.Document, *http.Response, error)
FetchRelated performs an outbound GET /resources/:id/relationship request
func FetchRelatedRequest ¶
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 ¶
FetchRequest returns a fully formatted JSONAPI Fetch request. Useful if you need to set custom headers before proceeding. Otherwise just use "jsh.Fetch".
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 ¶
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 ¶
NewRequest builds a basic request object with the necessary configurations to achieve JSON API compatibility
func ParseResponse ¶
ParseResponse handles parsing an HTTP response into a JSON Document if possible.
func Patch ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.