ordinary-sapphireO
Refine3y ago
4 replies
ordinary-sapphire

How to define custom path and api endpoint pairs?

In my scenario, I have a resource that looks like this:

{
  name: "letters",
  list: "/letters",
  create: "/letters/create",
  edit: "/letters/edit/:id",
  show: "/letters/show/:id",
  meta: {
    canDelete: true,
  },
}


However the API endpoints I need to call are different, for example, for the list page I want to call BASE_URL/api/dashboard/getletters
I managed to achieve that using
resource: "dashboard/allletters" in my custom useDataGrid() call. In this list I add a ShowButton, which links to /letters/show:id which should also call a different endpoint.

To implement the Show page I used the first example here: https://refine.dev/docs/api-reference/mui/components/basic-views/show/.

My problem is that using useShow with custom resource like this:
const { queryResult } = useShow({ resource: "dashboard/getletter" });

the query fails as it asks me to explicitly define id, as it cannot infer it that way, I assume because the resource at the top level is defined as /letters/show:id (which is the URL I want to be structured this way, for the client side).

So basically the question is if there is a way to map custom client path with a different api call path, or should I workaround and try to get the id directly from the URL in my Show page?

Thanks
Was this page helpful?