Why a page can't read another site's API, and how to serve it from your own

A browser only lets a page read a response from another origin when that server allows it with an Access-Control-Allow-Origin header; without the header, the page's code gets an error instead of the data, even when the request reached the server and it answered. The fix is a small endpoint on your own server that fetches the data and returns it from your own domain, because a server is not bound by that rule.

This is the usual reason a page that shows live numbers — usage, prices, a dashboard — works in a tool like curl and shows nothing in the browser.

How the block looks

Why the browser does this

Code loaded from one origin may only read responses from other origins when those responses say so. As the CORS guide puts it: a web application "can only request resources from the same origin the application was loaded from unless the response from other origins includes the right CORS headers" (MDN, CORS, checked 2026-11-12). An origin is the scheme, host and port together, so https://app.example.com and https://api.example.com are two origins even though the domain is the same.

The server opts in per response with one header:

Some requests are sent directly: a GET, HEAD or POST with only the safelisted headers and a content type of application/x-www-form-urlencoded, multipart/form-data or text/plain. Everything else — notably a POST with Content-Type: application/json — is preflighted: the browser sends an OPTIONS request first and only sends the real one if the server approves it (MDN, CORS, checked 2026-11-12). An API that was never written for browser pages usually answers neither.

Check the endpoint from the shell

Ask for the JSON the way a page from another origin would, by sending an Origin header and reading the response headers:

curl -sD - -o /dev/null -H "Origin: https://app.example.com" https://api.example.com/stats.json

The fix: fetch it on your own server

Your server can make any request it likes; only browsers apply the rule. One route that fetches the upstream and answers from your own domain is enough, and the page then talks to its own origin, where no check happens at all:

// GET /api/stats: the upstream JSON, served from your own domain
app.get("/api/stats", async (req, res) => {
  const r = await fetch("https://api.example.com/stats.json", { signal: AbortSignal.timeout(6000) });
  const body = await r.json();
  res.set("cache-control", "public, max-age=300");
  res.json(body);
});
// In the page: same origin, so nothing to allow
fetch("/api/stats").then((r) => r.json()).then(render);

Two things make the route hold up:

If you also own the API, adding the header there is one line, and often simpler than a proxy: Access-Control-Allow-Origin: https://app.example.com, or * for data that needs no cookies.

The investor site that explains how Cloudish works reads Cloudish's usage numbers this way: the stats come from a registry that doesn't send the header, so the site's server fetches them every five minutes and its page reads /api/stats from its own domain. (Cloudish is made by Hal9, which started this wiki; the example is the reason the page exists, not a recommendation.)

What not to do

See also

Glossary terms used on this page: API, API key, Host, Rate limit, Secret, Tool.

Sources

All checked on 2026-11-12.


First version written with AI assistance, from a site that needed another domain's live usage numbers and found the endpoint sent no CORS header, and checked against the sources on 2026-11-12. Found a mistake? Fix it or open an issue. Text licensed under CC BY 4.0.