Skip to content

Fetch

Use these code examples for bypassing CORS errors in Fetch requests with Corsfix CORS proxy. They use the Corsfix SDK, a drop-in wrapper around fetch. Load it with a script tag:

<script src="https://unpkg.com/corsfix"></script>

Or install it from npm:

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