Skip to content

white3km/elide-jsonapi-client

 
 

Repository files navigation

Elide JSON API Client

npm npm gzip size code coverage maintainability build status styled with prettier license

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.

Features

  • Built with Typescript!
  • Built on top of axios as a peer dependency
  • Supports Promises and async/await
  • JSON API response normalization
    • Flatter structure
    • Merges included relationship data
  • Serializes normalized resources back to a JSON API structure
    • Dates are converted to Unix epoch time for Elide
    • Protected fields can be omitted from being sent to the API
  • Supports JSON Patch Extension for bulk writes and complex mutations
  • Parameter serialization
    • Fields, filter, include, sort
    • Pagination: size & number OR offset & limit
  • Request caching and throttling

Basic Usage

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)

Known Issues

Request caching is not working with axios v0.19.0 due to a custom config bug.

Changelog

See CHANGELOG

To Do

See TODO

Contributing

See CONTRIBUTING

Credits

Bootstrapped with TypeScript library starter

Inspired by Kitsu

License

MIT

Packages

No packages published

Languages

  • TypeScript 97.9%
  • JavaScript 2.1%