Make api calls to a custom endpoint and not the resource name
Hi all , I currently have 4 resources : users , roles , permissions , providers . I want to update resource name to dashboard/user , dashboard/roles , etc. but still make api calls to {{BASE_URL}}/users | roles | permissions | providers only , not {{BASE_URL}}/dashboard/users | roles ...etc . How can i handle this use case ?
P.S. I thought of using identifier property of resources but its giving type error : identifier is not part of ResourceProp .
5 Replies
Hey @yeah_ush! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
----------------------
You can achieve this by using the
resource
property in data hooks. The resource
property allows you to specify a custom URL for API calls. You can keep the resource names as dashboard/user
, dashboard/roles
, etc., but make API calls to /users
, /roles
, /permissions
, and /providers
by specifying the resource
property in your data hooks.
For example, if you want to make a request to the URL /users
while using the resource name dashboard/user
, you can do the following:
This way, you can keep your resource names as dashboard/user
, dashboard/roles
, etc., but still make API calls to /users
, /roles
, /permissions
, and /providers
.
Source: FAQ - How can I request an API with nested route? (https://refine.dev/docs/faq)
----------------------FAQ | refine
How can I change the form data before submitting it to the API?
<@1020708912187576532> kapa.ai is still learning and improving, please let us how it did by reacting below
statutory-emerald•2y ago
but in this way i have to update all the hooks and what if I am using an Inferencer component
is there a better approach to this ??
You can use resource property of Inferencer component. https://refine.dev/docs/api-reference/antd/components/inferencer/#usage
Inferencer | refine
You can automatically generate views for your resources using @refinedev/inferencer. Inferencer exports AntdListInferencer, AntdShowInferencer, AntdEditInferencer, AntdCreateInferencer and AntdInferencer (which combines all in one place) components.