@dslab/ra-data-spring-rest
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

React-Admin Spring Data Rest

Version Documentation Maintenance License: MIT

Spring REST data provider for React-Admin

Install

yarn install @dslab/ra-data-spring-rest

Usage

To use the provider import and instantiate by passing the base apiUrl (required) and an httpClient (optional).

import springDataProvider from 'ra-data-spring-rest';

const dataProvider = springDataProvider('https://jsonplaceholder.typicode.com');

const App = () => <Admin dataProvider={dataProvider}></Admin>;

To add authorization headers provide a custom httpClient to the provider.

export const httpClientFactory = (): ((
    url: any,
    options?: fetchUtils.Options | undefined
) => Promise<{
    status: number,
    headers: Headers,
    body: string,
    json: any,
}>) => {
    return async (url: string, options: fetchUtils.Options = {}) => {
        if (!options.headers) {
            options.headers = new Headers({ Accept: 'application/json' });
        }
        if (!options.headers.has('Accept')) {
            options.headers.set('Accept', 'application/json');
        }

        const authHeader = 'Bearer TOKEN';
        if (authHeader) {
            options.headers.set('Authorization', authHeader);
        }

        return fetchUtils.fetchJson(url, options);
    };
};

const dataProvider = springDataProvider(
    'https://jsonplaceholder.typicode.com',
    httpClientFactory()
);

Author

SmartCommunityLab

Show your support

Give a ⭐️ if this project helped you!

License

Copyright © 2023 SmartCommunityLab.
This project is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i @dslab/ra-data-spring-rest

Weekly Downloads

12

Version

1.0.2

License

MIT

Unpacked Size

39.4 kB

Total Files

11

Last publish

Collaborators

  • dslab-admin
  • jcristofori
  • ffais
  • chin8