An opinionated {json:api} client for Elide based APIs
There are already a number of client libraries for working with JSON API, however this library is specifically designed for interacting with Elide based APIs, which has a few of it's own unique characteristics.
Promises
and async/await
size
& number
OR offset
& limit
import ApiClient from 'elide-jsonapi-client'
// Initialize a new client
const api = new ApiClient({
baseURL: 'http://localhost/api',
})
// Fetch a resource collection
const res = await api.fetch('articles')
// Create a resource
api.create('articles', {
type: 'articles',
title: 'Hello World',
})
// Update a resource
api.update('articles/1', {
id: '1',
type: 'articles',
title: 'Hello World!!!',
})
// Remove a resource
api.remove('articles', 1)
Inspired by Kitsu
Thanks goes to these wonderful people (emoji key):
Ken White ⚠️ 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome! See CONTRIBUTING guidelines.
Errors
A representation of a new Resource Object that
originates at the client and is yet to be created
on the server. The main difference between a regular
Resource Object is that this may not have an id
yet.
A Resource Operation
Operation Type constants
An array of Operations
Parameters
Relationships
A representation of a single resource
Either or a single Resource Object or an array of Resource Objects
An array of Resource Objects
Options
Merge arrays while preserving only unique items
array of primitives
array of unique items, e.g. [1,2,3]
Deserializes a JSON API response into a normalized structure
A resource object or collection of object
A normalized resource object or collection of objects
Destructures an Axios response error
Request error response
Hoists reltionship objects from the data
property to a root level property
A resource object
A flattened relationship object
Returns included relationship resources that match the provided relationship reference object
A collection of resource objects
A normalized resource object
Determines if a reference is an Array
Reference to check
Determines if a reference is defined
Reference to check
Determines if a reference is an 'Object'
Reference to check
Determines if a reference is a plain Object
.
A "plain" object is typically created by {}
or new Object()
.
Some types such as arrays and null, while technically objects,
are not considered plain objects.
Reference to check
Merges included relationship data with resource object relationships
A normalized object of relationship resources
The included relationship resources
A merged relationship object
Returns a collection of resources with only ID & Type properties
A normalized resource object or collection of resource objects
Normalizes a collection of resource objects
The collection of resources
Included relationship resources
A collection of normalized resource objects
Normalizes a resource by hoisting the attributes and linking relationships
A resource object
Included relationship resources
A normalized resource object
Converts a date string into Unix Epoch time
A date string
The time in milliseconds or the original value if it fails to parse
Serializes an object into a JSON API structure
A normalized resource object
Serialization options
A JSON API compliant resource object
Serializes normalized resources into a JSON API-PATCH structure
Operation to perform
Resource path relative to the root URL
Resources to serialize
Recursively stringifies nested objects
An object
The current query parameter
A URI component
Serializes a parameter object into a URL query string
Query parameters
Serialization options
A URL query string
Constructs a URL query string for JSON API parameters
Parameters to parse
Prefix returned string with ?
(default false
)
A URL query string
Throws if the provided relationship object doesn't have expected properties
Throws if the provided resource doesn't have expected properties
Generated using TypeDoc
Attribute of a Resource Object