Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
docs
src
test
.babelrc
.eslintrc.js
.gitignore
.npmrc
.prettierrc.js
LICENSE.txt
README.md
deploy.sh
index.js
package.json

README.md

@reststate/client

CircleCI

A lightweight client for making requests to a JSON:API service.

  • It doesn't attempt to provide a way to utilize every possible feature of JSON:API; instead, it offers a core set of functionality sufficient for most apps.
  • It doesn't attempt to abstract away the JSON:API object format; instead, it returns JSON:API data as-is.

@reststate/client provides a simple Promise-based API suitable for just about any JavaScript application. It doesn't handle persistence, though; for that, wrappers are available for a variety of popular state stores:

Synopsis

const resource = new Resource({
  name: 'widgets',
  httpClient: axios.create(...),
});

resource.loadAll()
  .then(widgets => widgets);

resource.create({
  attributes: {
    title: 'My Widget',
  },
});

Installation

$ npm install --save @reststate/client

@reststate/client needs to be configured with an httpClient object that handles the requests and responses. The easiest way to do this is to provide an axios instance configured with your server's base URL, the standard JSON:API content type, and optionally any authentication info your server requires.

import axios from 'axios';
import { Resource } from '@reststate/client';

const token = ...;

const httpClient = axios.create({
  baseUrl: 'https://sandboxapi.codingitwrong.com',
  headers: {
    'Content-Type': 'application/vnd+api.json',
    'Authentication': `Bearer ${token}`,
  },
});
const client = new Resource({ name: 'widgets', httpClient });

client.all().then(results => console.log(results));

Usage

For more information on usage, see the @reststate/mobx docs.

License

Apache-2.0

You can’t perform that action at this time.