like-gold
like-gold14mo ago

Refine cannot detect my backend PUT endpoint

I was following the JavaScript mastery tutorial on refine. The get, post and delete endpoints are working perfectly except for the put route which seems like it can be reached by refine. Instead of giving me an error about PUT. It returns an error saying cannot PATCH.. kindly help me solve this
5 Replies
kapa.ai
kapa.ai14mo ago
Hi @generalfib. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
kapa.ai
kapa.ai14mo ago
---------------------- It seems like you're using the default update function provided by the data provider, which uses the PATCH HTTP method. To change it to PUT, you can override the update function in your data provider. Here's an example of how to do this with the @refinedev/simple-rest data provider:
import dataProvider from "@refinedev/simple-rest";

const simpleRestProvider = dataProvider("API_URL");
const myDataProvider = {
...simpleRestProvider,
update: async ({ resource, id, variables }) => {
const url = `${apiUrl}/${resource}/${id}`;

const { data } = await httpClient.put(url, variables);

return {
data,
};
},
};

<Refine dataProvider={myDataProvider} />;
import dataProvider from "@refinedev/simple-rest";

const simpleRestProvider = dataProvider("API_URL");
const myDataProvider = {
...simpleRestProvider,
update: async ({ resource, id, variables }) => {
const url = `${apiUrl}/${resource}/${id}`;

const { data } = await httpClient.put(url, variables);

return {
data,
};
},
};

<Refine dataProvider={myDataProvider} />;
This code snippet overrides the update function to use the PUT method instead of PATCH. Replace "API_URL" with your actual API URL and use myDataProvider as the data provider for your Refine app. Source: refine.dev/docs/api-reference/core/providers/data-provider (https://refine.dev/docs/api-reference/core/providers/data-provider) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Data Provider | refine
The data provider acts as a data layer for your app that makes the HTTP requests and encapsulates how the data is retrieved. refine consumes these methods via data hooks.
kapa.ai
kapa.ai14mo ago
<@887715810599137300> kapa.ai is still learning and improving, please let us how it did by reacting below
fascinating-indigo
fascinating-indigo14mo ago
Hey @generalfib, Also, you can use meta.method to change HTTP method. You can find more information here: https://refine.dev/docs/packages/documentation/data-providers/simple-rest/#default-http-methods-and-customizing-them
like-gold
like-gold14mo ago
Thanks it really helped me