/elide-jsonapi-client

A JSON API client for Elide based APIs

Primary LanguageTypeScriptMIT LicenseMIT

Elide JSON API Client

npm npm gzip size code coverage maintainability build status styled with prettier All Contributors 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)

Documentation

Credits

Inspired by Kitsu

Contributors ✨

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.

License

MIT