Skip to main content
⚑
← Coursesβ€ΊFastAPI ProductionModule 6 Β· Real-World Patternsβ€ΊπŸ† Capstone: production-ready FastAPI checklistmission101 / 101
πŸ’¬ DiscussπŸ§ͺ Playground+250 XP
Task
πŸ“ **Task:** Build a `LoginIn` dataclass with `email: str` + `password: str` (write a `validate()` that raises `HTTPException` if email lacks '@' or password is shorter than 8 chars). Build a `LoginOut` dataclass with `user_id: int` + `token: str`. Build a `login(body: LoginIn) -> LoginOut` function that calls `body.validate()`, then returns `LoginOut(user_id=42, token=f'fake-{body.email}')`. Build `healthz() -> str` returning `'ok'` and `readyz() -> str` returning `'ok'`. Exercise: call `login(LoginIn('ada@example.com', 'supersecret'))` and print `.token`. Then call `login(LoginIn('bad', 'x'))` inside `try/except` and print the caught error message. Then call `healthz()` and `readyz()`. Expected output (4 lines): ``` fake-ada@example.com 400: invalid login ok ok ``` πŸ“‹ Implement the function above. Tests run automatically. πŸ’‘ **Hint:** Re-read the theory if stuck.

Keep going

✏️ Write your code here
🐍
Loading Python...
First visit only β€” ~5-10s. Stays cached afterward.
πŸ“Š Result
Press Run to see result...
πŸ“£ Help someone learn PythonShare this lesson with a friend β€” the first 15 are free, no signup.Tweet

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…