Provides a type alias and functions to create a new Json API document to be
encoded via JsonApi.Encode.document.
Creates a new Json API Document with no meta, no resource and a default
Json API version set to 1.0
myDocument : Document
myDocument =
buildRetrieves the Json API version.
From the json document above, jsonApiVersion will return "1.0"
Retrieves the meta object of the Document if it exists.
Retrieves the resource (in the data object) of the Document.
If there is no resource Nothing is returned.
If there are several resources, the first resource is returned.
Retrieves the resources (in the data array) of the Document.
If there is no resource set Nothing is returned.
If resources have been set but the list is empty, an empty list is also returned.
If there is only a resouce, a list with this resource is returned.
Retrieves the links object of the Document.
Sets the Json API version of the document
myDocument : Document
myDocument =
build
|> withJsonApiVersion "1.0"_The default version is 1.0
Sets the meta value of the Document
myDocument : Document
myDocument =
build
|> withMeta (object [ ( "redirect", bool True ) ])Sets the data value of the Json API Document to one resource.
myResource : Resource
myResource =
Resource.build "posts"
|> Resource.withId "post-1"
myDocument : Document
myDocument =
build
|> withResource myResourceSets the data value of the Json API Document to a list of resources.
myResources : List Resource
myResources =
[ Resource.build "posts"
|> Resource.withId "post-1"
, Resource.build "posts"
|> Resource.withId "post-2"
]
myDocument : Document
myDocument =
build
|> withResources myResourcesSets the links value of the Document
myDocument : Document
myDocument =
build
|> withLinks (Dict.fromList [ ( "self", "http://self" ) ])
The
Documentrepresents the global Json API document. This version of theDocumentis to be encoded viaJsonApi.Encode.document. Thus it has functions to create a newDocument.Example of json api document:
And how to build it with the
JsonApi.Encode.Documentmodule: