Admin in REST how to set path for list items
you can customize your restClient. for example i prefer to work with jsonServer
, so i have this in app.js
:
import customRestClient from './customRestClient'
const App = () => (
<Admin restClient={customRestClient('http://path.to.my.api/')}>
customRestClient
actually this file , I will bring it to my source, adjust the import.
This file is what your data is coming from your application to your api.
so in the function convertHTTPResponseToREST
you can just check resource
, and if there was one users
, you can access your data through
json.response.data
and return it toswitch
source to share
Thanks @pelak a lot. I am just writing code for your answer.
In your custom restClient provide the path to response data.
const convertHTTPResponseToREST = (response, type, resource, params) => {
const { headers, json } = response;
switch (type) {
case GET_LIST:
case GET_MANY_REFERENCE:
if (!headers.has('content-range')) {
throw new Error(
'The Content-Range header is missing in the HTTP Response. The simple REST client expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?'
);
}
// IF you just want use with **users** resource.
if(resource === 'users') {
return {
data: json.result,
total: parseInt(
headers
.get('content-range')
.split('/')
.pop(),
10
),
};
}
return {
data: json.result,
total: parseInt(
headers
.get('content-range')
.split('/')
.pop(),
10
),
};
case CREATE:
return { data: { ...params.data, id: json.id } };
default:
return { data: json };
}
};
Keyword: list in child, list of nests
source to share