How to make resources work for non-standard REST API structure

In a resource called campaigns, the list endpoint route can be /gw/campaign/fetch while the create endpoint can be /gw/campaign/create. And in another resource called dashboard, the list route being /gw/dashboard/all/fetch and the create endpoint route being /gw/dashboard/all/data/create. Note: These are not my only endpoints, there are many others that have different routes. How can I make this work in my resource?
2 Replies
kapa.ai
kapa.ai8mo ago
Hi @script4559. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, the resource prop is usually used as an API endpoint path. This is passed to the dataProvider as a parameter. However, the way it is handled depends on your dataProvider implementation. If you want to change the API endpoint path for a specific resource, you would need to modify your dataProvider to handle this. For your case, you can use different data providers for different resources. This might be a possible solution for your case. You can create a custom data provider for the "campaigns" and "dashboard" resources that uses the desired endpoint path. Here is the link to the documentation mentioned in the extract: Multiple Data Providers (https://refine.dev/docs/api-reference/core/providers/data-provider/#multiple-data-providers) In refine v4, you can define your actions (list, create, edit, show, clone) as paths instead of components. This will allow you to define custom routes for actions and take advantage of the full potential of your router without being restricted to the routes created automatically. Here's an example of how you can define your resources:
resources={[
{
name: "campaigns",
list: "/gw/campaign/fetch",
create: "/gw/campaign/create",
},
{
name: "dashboard",
list: "/gw/dashboard/all/fetch",
create: "/gw/dashboard/all/data/create",
}
]}
resources={[
{
name: "campaigns",
list: "/gw/campaign/fetch",
create: "/gw/campaign/create",
},
{
name: "dashboard",
list: "/gw/dashboard/all/fetch",
create: "/gw/dashboard/all/data/create",
}
]}
As you can see, the new enterprise-grade routing structure allows for effortless handling of multi-tenant structures. You can read more about it here (https://refine.dev/blog/refine-v4-announcement/#enterprise-grade-routing). Remember, this is only a resource definition, which must be handled within your router structure. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8mo ago
<@584066183989428345> kapa.ai is still learning and improving, please let us know how it did by reacting below