Skip to content

Getting Started

The quickest way to use Corsfix is with the Corsfix SDK. Replace fetch with corsfix.fetch, and your requests go through the proxy without CORS errors.

Add the SDK with a script tag:

<script src="https://unpkg.com/corsfix"></script>
<script>
corsfix
.fetch("https://api.example.com/data")
.then((response) => response.json())
.then((data) => console.log(data));
</script>

Or install it from npm:

Terminal window
npm install corsfix
import corsfix from "corsfix";
const response = await corsfix.fetch("https://api.example.com/data");

corsfix.fetch takes the same arguments as fetch:

// GET request
corsfix
.fetch("https://api.example.com/users")
.then((response) => response.json())
.then((data) => console.log(data));
// POST request
corsfix.fetch("https://api.example.com/users", {
method: "POST",
body: JSON.stringify({ name: "John" }),
headers: {
"Content-Type": "application/json",
},
});

If you would rather not use the SDK, add https://proxy.corsfix.com/? before your URL when making fetch requests. On live websites, this requires adding your domain in the dashboard and a paid plan.

// Add Corsfix URL before the API
// https://proxy.corsfix.com/? + https://api.example.com/data
fetch("https://proxy.corsfix.com/?https://api.example.com/data");

You should use the domain whitelist via the dashboard. If that’s not possible for your use case, you can fall back to using an API key.

fetch("https://proxy.corsfix.com/?https://api.example.com/data", {
headers: {
"x-corsfix-key": "cfx_12345678",
},
});

We discourage using API key on the client side, as it can be exposed in your source code and browser network requests.