Input
POST /users {"name": "Alice", "email": "alice@example.com"}Output
201 {"name": "Alice", "email": "alice@example.com"}Both fields are present and non-empty — the user is created.
Add a `POST /users` route to the FastAPI app in `main.py`. The route accepts a JSON body and creates a new user — but only if the payload is valid. Every field must be present and non-empty. Missing fields and empty str...
main.pyEditable starterPOST /users {"name": "Alice", "email": "alice@example.com"}201 {"name": "Alice", "email": "alice@example.com"}Both fields are present and non-empty — the user is created.
POST /users {"email": "alice@example.com"}400 {"error": "name is required"}name is missing from the payload.
This validates two required fields. Real APIs often validate dozens — format constraints, uniqueness checks, cross-field rules. How would you structure validation so adding a new rule is one line, not scattered conditionals?