Registry / devops / ra-data-simple-rest

ra-data-simple-rest

JSON →
library5.14.7jsnpmunverified

Simple REST data provider for react-admin, version 5.14.7. It maps react-admin CRUD queries to a REST API with a specific dialect: GET parameters for sorting, range, and filtering, and PUT for updates. The package is maintained as part of the react-admin ecosystem, with regular releases aligned with react-admin v5. It provides a straightforward bridge between react-admin and any REST API following the simple REST conventions (similar to FakeRest). Key differentiator: minimal configuration, just pass the API URL and optional custom HTTP client. Compared to ra-data-json-server, it offers more flexibility in URL structure and supports custom identifiers.

npm install ra-data-simple-rest
INSTALL
IMPORT
SIG · RA-DATA-SIMPLE-RES
R
ra-data-simple-rest
devopsjavascriptv5.14.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import simpleRestProvider from 'ra-data-simple-rest';
const simpleRestProvider = require('ra-data-simple-rest');
ESM-only since v5. CommonJS require will fail with newer Node versions or bundlers expecting named exports.
HttpClient
import { fetchUtils } from 'react-admin';
The HTTP client type is not exported from ra-data-simple-rest; use fetchUtils from react-admin.
DataProvider
import { DataProvider } from 'ra-core';
import simpleRestProvider from 'ra-data-simple-rest';
DataProvider type is imported from ra-core, not from this package.

Sets up a react-admin app with a simple REST backend using ra-data-simple-rest.

import { Admin, Resource } from 'react-admin'; import simpleRestProvider from 'ra-data-simple-rest'; import { PostList } from './posts'; const dataProvider = simpleRestProvider('http://my.api.url/'); const App = () => ( <Admin dataProvider={dataProvider}> <Resource name="posts" list={PostList} /> </Admin> ); export default App;
Debug
Known issues
gotchaThe getList response expects an array of records, not an object with a 'data' key. Some APIs return { data: [...] } which will break.
fix
If your API returns { data: [...] }, wrap it: const httpClient = (url, options) => fetchUtils.fetchJson(url, options).then(({ json }) => json.data);
affects: >=4.0
gotchaThe update and updateMany methods send a PUT request with full resource body. If your API expects PATCH, this will cause errors.
fix
Override update method or use a custom HTTP client that changes the method to PATCH.
affects: >=1.0
deprecatedThe package previously used CommonJS (require). v5 is ESM-only; calling require() will fail.
fix
Use import syntax or upgrade to a bundler that supports ESM.
affects: >=5.0
gotchaWhen using the built-in fetchUtils.fetchJson, HTTP errors (4xx/5xx) are thrown as Error objects. The data provider expects a rejected promise for network errors.
fix
Ensure your custom HTTP client rejects on HTTP errors, or handle them in the provider.
affects: >=1.0
gotchaThe deleteMany sends multiple DELETE requests sequentially, not in batch. Large deletions may be slow.
fix
Implement a custom deleteMany that sends a single batch DELETE request if your API supports it.
affects: >=1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'json')
The API returns a non-JSON response (e.g., HTML error page) or network request fails.
fix
Check the API URL and response; use a custom HTTP client with error handling.
Error: No token found in localStorage
The auth provider hasn't stored a token, or the code expects a token before auth.
fix
Ensure auth provider stores token in localStorage under 'auth' key before accessing data provider.
Uncaught (in promise) TypeError: Failed to fetch
CORS or network issue when making API call from browser.
fix
Enable CORS on the API server or use a proxy in development.
Upgrade
Version history
5.14.7latest on npm
Audit
Dependencies
ra-corerequiredPeer dependency required for DataProvider interface and types
Agent activity
6 hits · last 30 days
node
6
Resources
ra-data-simple-rest — npm install ra-data-simple-rest · libregistry