This repository was archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
JSON API Spec
Darko Kukovec edited this page Jan 8, 2018
·
8 revisions
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.
-
attributesandrelationshipsshouldn't use same properties - Possible collisions if
attributesorrelationshipscontain properties already used for internal Record needs
Version 3 has the same limitations as version 4 and some additional:
The following limitations are addressed in the v4:
-
attributesshouldn't contain atypeoridif they're different from the record type or id - If a local record is referenced in another record, then persisted on the server (id changed), the reference will be lost
- The lib is already setting the required headers, but you can also extend/override them if needed
- 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
Responseobject that has itserrorproperty set (message & HTTP status)
- The lib supports
data,errors,meta,links,included, andjsonapiproperties:-
data,errorandjsonapiare exsposed in theResponseobject -
includedis consumed by thesyncmethod -
metaandlinksvalues are available on the Record withgetMeta,getLinks,fetchLink,getRelationshipLinks,fetchRelationshipLinkand a computed meta property for relationships (record[relationshipName + 'Meta']
-
- The lib expects
idandtypeproperties, and they're available on theRecordinstance - If the resource has
attributes, they will be available as regular properties on theRecordinstance - If the resource has
relationships-
linkswill be available using thegetRelationshipLinksmethod on the record- Use
fetchRelationshipLinkto 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:record[relName]. Also, the id is available onrecord[relName + 'Id'] - If the model is "unknown", the id will be available on
record[relName + 'Id']
- If the store already contains the referenced model or
-
metais available onrecord[relName + 'Meta']
-
- If the resource has
linksormeta, they will be available with thegetLinksandgetMetamethods on the record- Use
fetchLinkto fetch the link
- Use
- The lib expects
idandtype -
metais available onrecord[relName + 'Meta']
- 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
- The
metaproperty will be available directly on theResponseobject
- 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 Promise that will resolve to aResponsewith either thedataorerrorproperty set- The link is lazily evaluated, so the request won't be made until you access the property
- The link can be a string with an URL
- The
jsonapiproperty is available on theResponseobject instance
- 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 asrecord['first-name']
- Fetch top-level
links - Fetch resource-level
linkswithfetchLink - Fetch
relatedlink from relationship-levellinkswithfetchRelationshipLink
- Fetch relationship-level
linkswithfetchRelationshipLink
- Supported by providing a
includeproperty in the request options (IRequestOptions)
- Supported by providing a
fieldsproperty in the request options (IRequestOptions)
- Supported by providing a
sortproperty in the request options (IRequestOptions)
- 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
- Supported by providing a
filterproperty in the request options (IRequestOptions)
- 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 is supported using the
savemethod if the record was not created on the client
- Direct update of relationships is supported with the
saveRelationshipmethod -
Tip: If you want to add a new relationship, use
assignRef
- The resource can be deleted with the
removemethod on the record
- All current communication with the server is using the required naming method
- The lib will process all HTTP status 400+ as errors
- The error objects will be available in the
Responseobject under theerrorproperty (without any modification)