how to add custom headers by useCustom ?

how to add custom headers by useCustom ?
2 Replies
kapa.ai
kapa.ai3w ago
Hi @tingadev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To add custom headers using the useCustom hook in refine, you can utilize the config.headers property. Here's how you can do it:
import { useCustom } from "@refinedev/core";

const { data, isLoading } = useCustom({
url: "your-api-endpoint",
method: "get",
config: {
headers: {
"x-custom-header": "foo-bar",
},
},
});
import { useCustom } from "@refinedev/core";

const { data, isLoading } = useCustom({
url: "your-api-endpoint",
method: "get",
config: {
headers: {
"x-custom-header": "foo-bar",
},
},
});
In this example, we're adding a custom header "x-custom-header" with the value "foo-bar" to the request. The config.headers property allows you to specify custom headers for your API request. These headers will be passed to the custom method of your data provider. You can add multiple headers as needed:
config: {
headers: {
"x-custom-header-1": "value1",
"x-custom-header-2": "value2",
// ... more headers
},
},
config: {
headers: {
"x-custom-header-1": "value1",
"x-custom-header-2": "value2",
// ... more headers
},
},
This approach is documented in the useCustom Properties section of the refine documentation. Remember that the exact behavior might depend on your data provider implementation. Make sure your data provider correctly handles the headers passed through the config object. useCustom Properties ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@761921731505946634> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?