ra-data-json-server is a data provider specifically designed to integrate `react-admin` applications with REST APIs that follow the conventions of JSON Server, including services like JSONPlaceholder. It translates `react-admin` data requests (e.g., `getList`, `getOne`, `create`) into standard HTTP requests compatible with a JSON Server backend. The package is currently at version 5.14.5 and is actively maintained, with frequent patch releases addressing bug fixes and minor improvements, usually on a weekly or bi-weekly basis, following the `react-admin` release cycle. A key differentiator is its strict adherence to JSON Server's REST dialect, simplifying setup for prototyping or light backend needs, and requiring specific HTTP headers like `X-Total-Count` for proper pagination.
npm install ra-data-json-serverVerified import paths — ran on the pinned version, not inferred.
Initializes a `react-admin` application with `ra-data-json-server` connected to JSONPlaceholder, defining 'posts' and 'users' resources.
Configure your backend to include an `X-Total-Count` header in the response, e.g., `X-Total-Count: 319`. If your API is on a different domain, ensure `Access-Control-Expose-Headers: X-Total-Count` is set in your CORS policy.
Ensure your backend includes the `Access-Control-Expose-Headers: X-Total-Count` header in its CORS policy to allow the browser to read the `X-Total-Count` response header.
For better performance on batch operations, consider creating a custom `httpClient` that intercepts and optimizes `updateMany`/`deleteMany` requests, or use a data provider designed for your specific backend that supports batch operations natively.
Upgrade to `ra-data-json-server@5.14.5` or later to ensure proper handling of `id=0` and correct form state management for nested fields.
Verify that your backend sends the `X-Total-Count` header. If using a different domain for your API, ensure `Access-Control-Expose-Headers: X-Total-Count` is configured in your backend's CORS policy.
Configure your backend server to include appropriate `Access-Control-Allow-Origin` headers (e.g., `Access-Control-Allow-Origin: *` for development, or specific origins in production) and `Access-Control-Expose-Headers` for `X-Total-Count`.
Inspect network requests to confirm the `X-Total-Count` header is present and readable. Also, ensure your API's primary key field is named `id` as expected by default, or provide a custom `id` mapper if it's named differently.