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, andjsonapiproperties:data,errorandjsonapiare exsposed in theResponseobjectincludedis consumed by thesyncmethodmetaandlinksvalues are available on the model withgetModelMeta,getModelLinks,fetchModelLink,getModelRefLinks,fetchModelRefLinkandgetModelRefMeta.
Resource Objects
The lib expects
idandtypeproperties, and they're available on theModelinstanceIf the resource has
attributes, they will be available as regular properties on theModelinstanceIf the resource has
relationshipslinkswill be available using thegetModelRefpLinksmethod on the record- Use
fetchModelRefLinkto fetch the link
- Use
datawill be used to build the references between models- If the store already contains the referenced model or
includescontains 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
metais available withgetModelRefMeta
If the resource has
linksormeta, they will be available with thegetLinksandgetMetamethods on the record- Use
fetchLinkto fetch the link
- Use
Resource Identifier Objects
- The lib expects
idandtype metais available with (getModelMeta)[jsonapi-utils#getmodelmeta]
Compound Objects
- The lib supports
includedproperty - The lib will add
includedresources as references to thedataresources - The
includedresources are treated as regular records, just like thedataresources, with same features and limitations
Meta Information
The meta property will be available directly on the Response object
Links
- The
linksproperty is supported, and exposes all links directly on theResponseobject - They are also available in raw form as a
linksproperty on theResponseobject response[linkName]is a function that returns Promise that will resolve to aResponsewith either thedataorerrorproperty 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
linkswithfetchModelLink - Fetch
relatedlink from relationship-levellinkswithfetchModelRefLink
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
linksproperty of theResponseobject instance - The lib allows pagination with links, e.g.
response.nextwill return a Promise that will resolve to aResponseobject with either thedataorerrorproperty 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
savemethod if the record was created on the client - Client-Generated IDs are supported
- set
useAutogeneratedIdstotrue - override
autoIdFunctionso 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
saveRelationshipmethod - 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)