在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:henvo/ra-jsonapi-client开源软件地址:https://github.com/henvo/ra-jsonapi-client开源编程语言:JavaScript 100.0%开源软件介绍:ra-jsonapi-clientA JSONAPI compatible data provider for react-admin. FeaturesCurrently these actions are supported:
Installation# via npm
npm install ra-jsonapi-client
# via yarn
yarn add ra-jsonapi-client UsageImport 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 "ra-jsonapi-client";
const dataProvider = jsonapiClient('http://localhost:3000');
const App = () => (
<Admin dashboard={Dashboard} dataProvider={dataProvider}>
...
</Admin>
);
export default App; OptionsThis 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); Total countSince JSONAPI does not specify a standard for the total count key in the meta object, you can set it with: const settings = { total: 'total-count' }; Which will work for: {
"data": { ... },
"meta": {
"total-count": 436
}
} If this option is not set it will fall back to In addition, if your server doesn't provide a count field, you can set total
count to const dataProvider = jsonapiClient('http://localhost:3000', { total: null }); Custom HTTP headersCustom headers can be set by providing a 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',
} AuthenticationThis 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 authFor basic auth your authProvider needs to store username and password like this: localStorage.setItem('username', 'bob');
localStorage.setItem('password', 'secret'); Bearer TokenFor 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 {
// Set the update method from PATCH to PUT.
updateMethod: 'PUT'
}
Array format for |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论