Skip to content

Fetch

Use these code examples for bypassing CORS errors in Fetch requests with Corsfix CORS proxy.

fetch("https://proxy.corsfix.com/?https://api.example.com/data");
fetch("https://proxy.corsfix.com/?https://api.example.com/data", {
headers: {
"x-corsfix-cache": "15m",
},
});
fetch("https://proxy.corsfix.com/?https://api.example.com/data", {
method: "POST",
body: JSON.stringify({
data: "mydata",
}),
});
fetch(
"https://proxy.corsfix.com/?" +
"https://api.example.com/data?key={{SECRET_KEY}}",
{
method: "POST",
headers: {
Authorization: "Bearer {{SECRET_TOKEN}}",
},
body: JSON.stringify({
data: "mydata",
}),
}
);
fetch("https://proxy.corsfix.com/?https://api.example.com/data", {
headers: {
"x-corsfix-headers": JSON.stringify({
"User-Agent": "MyAgent/1.0",
}),
},
});

If you would rather not build the proxy URL yourself, the Corsfix SDK wraps fetch for you. It takes the same arguments as fetch, with Corsfix features in the corsfix option.

import corsfix from "corsfix";
corsfix.fetch("https://api.example.com/data", {
corsfix: { cache: "15m" },
});