SOARDO
Software Engineer (SDE)fastapibeginner3 interactive MCQs in app

Response Models, Status Codes & JSONResponse

response_model data filtering & secret strippingsemantic HTTP 201 / 202 / 204 status codesORM model_config = ConfigDict(from_attributes=True)

Setting `response_model=PublicUserOut` and `status_code=status.HTTP_201_CREATED` filters, validates, and documents outgoing responses—**stripping sensitive DB fields (`password_hash`, `expected_answer`, `correct_option_index`) automatically before JSON serialization!** Never return raw ORM/DB dicts directly when internal columns exist. Return explicit `201 Created` on resource creation, `204 No Content` (`Response(status_code=204)`) on deletes, and `202 Accepted` on async evaluation jobs!

`@app.post("/users", response_model=PublicUser, status_code=201)` automatically removes `password_hash` from the returned DB row before sending JSON!
omitting `response_model` leaks server secrets/columns added later in DB migrations straight to clients!
FastAPI — Response Model (Official)read ↗Response Models, Status Codes & JSONResponse — Applied Practicepractice ↗

Practice Response Models, Status Codes & JSONResponse with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides