React-Admin Spring Data Rest
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
- Website: http://www.smartcommunitylab.it/
- Github: @smartcommunitylab
Show your support
Give a ⭐️ if this project helped you!
License
Copyright © 2023 SmartCommunityLab.
This project is MIT licensed.