API & Integrations
Solution proposed
Example from the ReviewMyCodes team
FastAPI backend blocked by CORS when called from my React app
Description
My React app (http://localhost:5173) calls my FastAPI API (http://localhost:8000). The request works in Postman but fails in the browser.
— This is an example problem from the ReviewMyCodes team, showing how a good question looks. Real community questions appear alongside it.
Expected
The browser should receive the JSON response.
Actual
Access to fetch at 'http://localhost:8000/items' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Steps to reproduce
- Start FastAPI with uvicorn
- Start the React dev server
- Click "Load items"
Code
python
from fastapi import FastAPI
app = FastAPI()
@app.get("/items")
def list_items():
return [{"id": 1, "name": "Keyboard"}]