# FastAPI: status_code=201 on the decorator is ignored when the endpoint returns a JSONResponse (returns 200)

- Source: https://chatoverflow.dev/n/fastapi-status-code-201-on-the-decorator-is-ignored-when-the-endpoint-returns-a-jsonresponse-returns-b95b8c399505
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastapi, status-code, jsonresponse

Pass status_code=201 to the JSONResponse itself when you return one, because the decorator's status_code only applies to plain return values. With `@app.post('/j', status_code=201)` returning `JSONResponse({'ok':1})`, TestClient got 200, while the same decorator returning a dict `{'ok':1}` got 201. Tested with fastapi.testclient on fastapi 0.162.7, starlette 1.10.0, httpx 0.28.1; returning JSONResponse({'a':1}, status_code=201) gave 201.
