This repository has been 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.
-
attributes
andrelationships
shouldn't use same properties - Possible collisions if
attributes
orrelationships
contain 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:
-
attributes
shouldn't contain atype
orid
if 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
Response
object that has itserror
property set (message & HTTP status)
- The lib supports
data
,errors
,meta
,links
,included
, andjsonapi
properties:-
data
,error
andjsonapi
are exsposed in theResponse
object -
included
is consumed by thesync
method -
meta
andlinks
values are available on the Record withgetMeta
,getLinks
,fetchLink
,getRelationshipLinks
,fetchRelationshipLink
and a computed meta property for relationships (record[relationshipName + 'Meta']
-
- The lib expects
id
andtype
properties, and they're available on theRecord
instance - If the resource has
attributes
, they will be available as regular properties on theRecord
instance - If the resource has
relationships
-
links
will be available using thegetRelationshipLinks
method on the record- Use
fetchRelationshipLink
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: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
-
meta
is available onrecord[relName + 'Meta']
-
- If the resource has
links
ormeta
, they will be available with thegetLinks
andgetMeta
methods on the record- Use
fetchLink
to fetch the link
- Use
- The lib expects
id
andtype
-
meta
is available onrecord[relName + 'Meta']
- 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
- The
meta
property will be available directly on theResponse
object
- 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 Promise that will resolve to aResponse
with either thedata
orerror
property 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
jsonapi
property is available on theResponse
object 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
links
withfetchLink
- Fetch
related
link from relationship-levellinks
withfetchRelationshipLink
- Fetch relationship-level
links
withfetchRelationshipLink
- Supported by providing a
include
property in the request options (IRequestOptions
)
- Supported by providing a
fields
property in the request options (IRequestOptions
)
- Supported by providing a
sort
property in the request options (IRequestOptions
)
- 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
- Supported by providing a
filter
property in the request options (IRequestOptions
)
- 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 is supported using the
save
method if the record was not created on the client
- Direct update of relationships is supported with the
saveRelationship
method -
Tip: If you want to add a new relationship, use
assignRef
- The resource can be deleted with the
remove
method 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
Response
object under theerror
property (without any modification)