Documentation ¶
Overview ¶
Package rest is a collection of utilities based around json, JSON:API, and other useful REST request and response features.
Index ¶
- func JSONAPIErrorResponse(statusCode int, err error) string
- func MarshalAsJSONString(someInput interface{}) (string, error)
- func SerializeAsJSONAPIDocument(someJSONAPIStruct interface{}) (string, error)
- func UnmarshalJSONAPIDocument(documentJSON []byte, inputStruct interface{}) error
- func UnmarshalJSONString(someString string, object interface{}) error
- func UnmarshalManyJSONAPIDocument(documentJSON []byte, inputStruct interface{}) ([]interface{}, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONAPIErrorResponse ¶ added in v1.9.4
JSONAPIErrorResponse takes a status code and an error object and serializes a JSON:API conformant error document.
func MarshalAsJSONString ¶ added in v1.9.4
MarshalAsJSONString marshals a struct as a jsonString. Returns any errors.
func SerializeAsJSONAPIDocument ¶ added in v1.9.4
SerializeAsJSONAPIDocument serializes the given struct pointer, or slice of struct pointers, as a jsonapi document. Must be annotated with proper jsonapi annotations. see: https://github.com/google/jsonapi#jsonapi-tag-reference for info on how to annotate your structs.
func UnmarshalJSONAPIDocument ¶ added in v1.9.4
UnmarshalJSONAPIDocument takes a JSON API document (json) as a byte slice and attempts to deserialize the data into a json api conformant struct pointer. Returns any errors.
func UnmarshalJSONString ¶ added in v1.9.4
UnmarshalJSONString unmarshals a JSON String into a passed struct. You should be passing in a pointer. Returns any errors. For example:
var structToBePopulated MyStruct rest.UnmarshalJSONString(jsonString, &structToBePopulated)
or
var structToBePopulated *MyStruct rest.UnmarshalJSONString(jsonString, structToBePopulated)
func UnmarshalManyJSONAPIDocument ¶ added in v1.9.4
func UnmarshalManyJSONAPIDocument(documentJSON []byte, inputStruct interface{}) ([]interface{}, error)
UnmarshalManyJSONAPIDocument unmarshals a json api document that contains many payloads and returns a slice of structs that match the type of the inputStruct. therefore, the inputStruct passed must be the same type as the struct mapped to the JSONAPI payload.
Types ¶
This section is empty.