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 string, resourceType string, id string, action string) (*jsh.Document, *http.Response, error)
- func ActionRequest(baseURL string, resourceType, id string, action string) (*http.Request, error)
- func Delete(urlStr string, resourceType string, id string) (*http.Response, error)
- func DeleteRequest(urlStr string, resourceType string, 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 FetchRequest(baseURL string, resourceType, id string) (*http.Request, error)
- func List(baseURL string, resourceType string) (*jsh.Document, *http.Response, error)
- func ListRequest(baseURL string, resourceType string) (*http.Request, error)
- func NewRequest(method string, 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 PatchRequest(baseURL string, object *jsh.Object) (*http.Request, error)
- func Post(baseURL string, object *jsh.Object) (*jsh.Document, *http.Response, error)
- func PostRequest(baseURL string, object *jsh.Object) (*http.Request, error)
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 ¶
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 ¶
Delete allows a user to make an outbound "DELETE /resource/:id" request.
resp, err := jsh.Delete("http://apiserver", "user", "2")
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 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 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 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".
Types ¶
This section is empty.