Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

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.

Limitations

v4 limitations

  • attributes and relationships shouldn't use same properties
  • Possible collisions if attributes or relationships contain properties already used for internal Record needs

v3 limitations

Version 3 has the same limitations as version 4 and some additional:

The following limitations are addressed in the v4:

  • attributes shouldn't contain a type or id 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
  • 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)
  • The lib expects id and type properties, and they're available on the Record instance
  • If the resource has attributes, they will be available as regular properties on the Record instance
  • If the resource has relationships
    • links will be available using the getRelationshipLinks method on the record
    • 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 on record[relName + 'Id']
      • If the model is "unknown", the id will be available on record[relName + 'Id']
    • meta is available on record[relName + 'Meta']
  • If the resource has links or meta, they will be available with the getLinks and getMeta methods on the record
  • The lib expects id and type
  • meta is available on record[relName + 'Meta']
  • The lib supports included property
  • The lib will add included resources as references to the data resources
  • The included resources are treated as regular records, just like the data resources, with same features and limitations
  • The meta property will be available directly on the Response object
  • The links property is supported, and exposes all links directly on the Response object
  • They are also available in raw form as a links property on the Response object
  • response[linkName] is a Promise that will resolve to a Response with either the data or error 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 the Response 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 as record['first-name']
  • 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 the Response object instance
  • The lib allows pagination with links, e.g. response.next will return a Promise that will resolve to a Response object with either the data or error 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
  • 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 the error property (without any modification)