Spec compliance
Based on the official v1.0 specification, all the features should be implemented. If something is missing or not behaving correctly, feel free to open an issue.
Content Negotiation
Client Responsibilities
The lib is already setting the required headers, but you can also extend/override them if needed
Server Responsibilities
If the server returns any HTTP status 400 or greater (including 406 and 415 mentioned in the spec), the request promise will reject with a Response
object that has its error
property set (message & HTTP status)
Document Structure
Top Level
- The lib supports
data
,errors
,meta
,links
,included
, andjsonapi
properties:data
,error
andjsonapi
are exsposed in theResponse
objectincluded
is consumed by thesync
methodmeta
andlinks
values are available on the model withgetModelMeta
,getModelLinks
,fetchModelLink
,getModelRefLinks
,fetchModelRefLink
andgetModelRefMeta
.
Resource Objects
The lib expects
id
andtype
properties, and they're available on theModel
instanceIf the resource has
attributes
, they will be available as regular properties on theModel
instanceIf the resource has
relationships
links
will be available using thegetModelRefpLinks
method on the record- Use
fetchModelRefLink
to fetch the link
- Use
data
will be used to build the references between models- If the store already contains the referenced model or
includes
contains the model it will be available right away on the record:model[relName]
. Also, the id is available onmodel.meta.refs[relName]
- If the model is "unknown", the id will be available on
model.meta.refs[relName]
- If the store already contains the referenced model or
meta
is available withgetModelRefMeta
If the resource has
links
ormeta
, they will be available with thegetLinks
andgetMeta
methods on the record- Use
fetchLink
to fetch the link
- Use
Resource Identifier Objects
- The lib expects
id
andtype
meta
is available with (getModelMeta
)[jsonapi-utils#getmodelmeta]
Compound Objects
- The lib supports
included
property - The lib will add
included
resources as references to thedata
resources - The
included
resources are treated as regular records, just like thedata
resources, with same features and limitations
Meta Information
The meta
property will be available directly on the Response
object
Links
- The
links
property is supported, and exposes all links directly on theResponse
object - They are also available in raw form as a
links
property on theResponse
object response[linkName]
is a function that returns Promise that will resolve to aResponse
with either thedata
orerror
property set. The link can be a string with an URL.
JSON API Object
The jsonapi
property is available on the Response
object instance
Member Names
- All member names are treated as strings, therefore adhere to the specification
- If a name is not a valid variable name, e.g.
"first-name"
, you can access it asmodel['first-name']
Fetching Data
Fetching Resources
- Fetch top-level
links
- Fetch resource-level
links
withfetchModelLink
- Fetch
related
link from relationship-levellinks
withfetchModelRefLink
Fetching Relationships
Fetch relationship-level links
with fetchModelRefLink
Inclusion of Related Resources
Supported by providing a include
property in the request options (IRequestOptions
)
Sparse Fieldsets
Supported by providing a fields
property in the request options (IRequestOptions
)
Sorting
Supported by providing a sort
property in the request options (IRequestOptions
)
Pagination
- The lib supports top-level links
- The lib allows access to raw links in the
links
property of theResponse
object instance - The lib allows pagination with links, e.g.
response.next
will return a Promise that will resolve to aResponse
object with either thedata
orerror
property set- The link is lazily evaluated, so the request won't be made until you access the property
Filtering
Supported by providing a filter
property in the request options (IRequestOptions
)
Creating, Updating and Deleting Resources
Creating Resources
- Creating resources is supported using the
save
method if the record was created on the client - Client-Generated IDs are supported
- set
useAutogeneratedIds
totrue
- override
autoIdFunction
so it returns a valid UUID
- set
Updating Resources
Updating resources is supported using the save
method if the record was not created on the client
Updating Relationships
- Direct update of relationships is supported with the
saveRelationship
method - Tip: If you want to add a new relationship, use
initModelRef
Deleting Resources
The resource can be deleted with the destroy
method on the record
Query Parameters
All current communication with the server is using the required naming method
Errors
Processing Errors
The lib will process all HTTP status 400+ as errors
Error Objects
The error objects will be available in the Response
object under the error
property (without any modification)