Fetch
Use these code examples for bypassing CORS errors in Fetch requests with Corsfix CORS proxy.
GET Request
Section titled “GET Request”fetch("https://proxy.corsfix.com/?https://api.example.com/data");
Cached Response
Section titled “Cached Response”fetch("https://proxy.corsfix.com/?https://api.example.com/data", { headers: { "x-corsfix-cache": "true", },});
POST Request
Section titled “POST Request”fetch("https://proxy.corsfix.com/?https://api.example.com/data", { method: "POST", body: JSON.stringify({ data: "mydata", }),});
Using Secrets
Section titled “Using Secrets”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", }), });
Header Override
Section titled “Header Override”fetch("https://proxy.corsfix.com/?https://api.example.com/data", { headers: { "x-corsfix-headers": JSON.stringify({ "User-Agent": "MyAgent/1.0", }), },});