Beginner question: why does my fetch request work in Postman but fail in the browser?
I'm calling an API from a small web page. Same URL, same headers, works fine in Postman. In the browser the console shows an error mentioning CORS and the request is blocked.
I've read that it's a browser security thing, but I don't understand why the browser cares when Postman doesn't. Is this something I fix in my code, or does the API server have to change?
Comments · 3
Quick explanation: browsers enforce CORS to protect users, so a page on one site can't read responses from another unless that server allows it with headers. Postman isn't a browser, so it doesn't enforce it.
The API server has to send Access-Control-Allow-Origin for your origin. You can't fix it from the frontend alone.
If you don't control the API, put a small proxy on your own server and call that from the page. Don't use random public CORS proxies for anything with keys.