Nonchalantly Perusing Magazines
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

jsonapi-league-fractal

1.0.12 • Public • Published

Data provider for integration react admin and league fractal

npm version

A JSONAPI compatible data provider for react-admin. Module integration with league fractal.

Features

Currently these actions are supported:

  • GET_LIST
  • GET_ONE
  • CREATE
  • UPDATE
  • DELETE
  • GET_MANY
  • GET_MANY_REFERENCE

Installation

# via npm 
npm install jsonapi-league-fractal
 
# via yarn 
yarn add jsonapi-league-fractal

Usage

Import this package, set the base url and pass it as the dataProvider to react-admin.

//in app.js
import React from "react";
import { Admin, Resource } from "react-admin";
import jsonapiClient from "jsonapi-league-fractal";
 
const dataProvider = jsonapiClient('http://localhost:3000');
 
const App = () => (
  <Admin dashboard={Dashboard} dataProvider={dataProvider}>
    ...
  </Admin>
);
 
export default App;

Options

This client allows you to set some optional settings as the second parameter:

// Configure some settings.
const settings = { ... };
 
// Pass it as the second parameter after the base URL.
const dataProvider = jsonapiClient('http://localhost:3000', settings);

Custom HTTP headers

Custom headers can be set by providing a headers object in options:

const settings = {
  headers: {
    Authorization: 'Bearer ...',
    'X-Requested-With': 'XMLHttpRequest'
  }
}

The default value is:

{
  Accept: 'application/vnd.api+json; charset=utf-8',
  'Content-Type': 'application/vnd.api+json; charset=utf-8',
}

Authentication

This client assumes that you are using an authProvider for your react-admin application. In order to use authentication with your backend your authProvider needs to store credentials in localStorage.

Basic auth

For basic auth your authProvider needs to store username and password like this:

localStorage.setItem('username', 'bob');
localStorage.setItem('password', 'secret');

Bearer Token

For authentication via (access) token your authProvider needs to store the token like this:

localStorage.setItem('token', '123token');

Update method (PUT vs. PATCH)

First versions used PUT as the default update HTTP method. In version 0.5.0 this was changed to PATCH since it complies with the JSONAPI standard.. You can still use PUT by declaring the update method in the settings:

{
  // Set the update method from PATCH to PUT.
  updateMethod: 'PUT'
}

Array format for GET_MANY filter

This package makes usage of the aweseome qs querystring parsing library.

Default: brackets Options: indices, repeat, comma

Contributors

Install

npm i jsonapi-league-fractal

DownloadsWeekly Downloads

5

Version

1.0.12

License

MIT

Unpacked Size

34.2 kB

Total Files

30

Last publish

Collaborators

  • avatar