rest

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package rest is a collection of utilities based around json, JSON:API, and other useful REST request and response features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONAPIErrorResponse added in v1.9.4

func JSONAPIErrorResponse(statusCode int, err error) string

JSONAPIErrorResponse takes a status code and an error object and serializes a JSON:API conformant error document.

func MarshalAsJSONString added in v1.9.4

func MarshalAsJSONString(someInput interface{}) (string, error)

MarshalAsJSONString marshals a struct as a jsonString. Returns any errors.

func SerializeAsJSONAPIDocument added in v1.9.4

func SerializeAsJSONAPIDocument(someJSONAPIStruct interface{}) (string, error)

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

func UnmarshalJSONAPIDocument(documentJSON []byte, inputStruct interface{}) error

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

func UnmarshalJSONString(someString string, object interface{}) error

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.

Jump to

Keyboard shortcuts

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