I am trying to use the ra-data-simple-rest data provider.
import React from 'react';
import { Admin, fetchUtils, Resource } from 'react-admin';
import simpleRestProvider from 'ra-data-simple-rest';
import { PostList } from './Posts';
const dataProvider = simpleRestProvider('http://localhost:8000');
const App = () => (
<Admin dataProvider={dataProvider}>
<Resource name="posts" list={PostList} />
</Admin>
);
export default App;
The react-admin listens to http://localhost:3000/#/posts
Api is running on : http://localhost:8000/posts which returns response as.
$response = new JsonResponse($output);
$response->headers->set('Content-Range', 'posts 0-0/5');
$response->headers->set('Access-Control-Expose-Headers', 'Content-Range');
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
which retuns something as
{
"data": [
{
"id": "1",
"title": "Hello world",
"body": "Hello world"
},
{
"id": "2",
"title": "Hello world",
"body": "Hello world"
}
],
"total": 2
}
I am getting an error as
The response to 'GET_LIST' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'GET_LIST'
If the data
key is removed as
[
{
"id": "1",
"title": "Hello world",
"body": "Hello world"
},
{
"id": "2",
"title": "Hello world",
"body": "Hello world"
}
]
is getting the result.
Failed to Fetch
was shown on red colour and it was due to more CORS related issue. So added appropriate headers. Current issue is withThe response to 'GET_LIST' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'GET_LIST'
– Chord