CORS for API builders
What cross-origin resource sharing is, why browsers block requests, and how to configure CORS without opening the API to the world.
CORS is a browser rule, not a firewall
CORS (Cross-Origin Resource Sharing) tells a browser whether JavaScript on origin A may read a response from origin B. curl, servers and mobile apps are not bound by it. Never treat CORS as your only authorization.
The usual setup
- Your API lists specific front-end origins (
https://app.example.com), not*, if you use cookies or tokens in browsers. - Preflight (
OPTIONS) must allow the methods and headers you actually use. Access-Control-Allow-Credentials: truecannot be paired with*.
Debugging
If it works in curl and fails in the browser, read the console — it is often a missing header or a trailing-slash origin mismatch. See REST fundamentals and HTTP caching (caches and CORS interact).
Related
Last verified: August 2026. Technology and pricing change — always confirm current details with the vendor.