Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesFastAPI ProductionModule 6 · Real-World Patterns🏆 Capstone: production-ready FastAPI checklistmission105 / 105
+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.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
📊 Result
Press Run to see result...

💬 Discussion

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