Response Status Code
Default Status Code
Section titled “Default Status Code”JustAPI returns 200 OK by default for successful responses.
Custom Status Code
Section titled “Custom Status Code”Use status_code in the decorator:
from justapi import JustAPIApp
app = JustAPIApp()
@app.post("/items", status_code=201)def create_item(): return {"message": "created"}Common Status Codes
Section titled “Common Status Codes”| Code | Meaning | Use When |
|---|---|---|
| 200 | OK | GET, successful PUT/PATCH |
| 201 | Created | Successful POST |
| 204 | No Content | Successful DELETE |
| 301 | Moved Permanently | Redirect |
| 400 | Bad Request | Client error |
| 401 | Unauthorized | Authentication required |
| 403 | Forbidden | Authenticated but not authorized |
| 404 | Not Found | Resource doesn’t exist |
| 422 | Unprocessable Entity | Validation error |
Returning a Response Directly
Section titled “Returning a Response Directly”For full control, return a Response object:
from starlette.responses import JSONResponse
@app.get("/custom")def custom_response(): return JSONResponse( content={"message": "custom"}, status_code=202, headers={"X-Custom": "header"}, )See Also
Section titled “See Also”- Handling Errors — exception handlers
- Additional Status Codes — advanced status code patterns
- Status Codes Reference — all available status codes