MongoDB with FastAPI & Python

Lesson 6 of 6

Final Project: Build a Task API with FastAPI & MongoDB

Time to combine models, Motor, and path operations into a real API.

Requirements

  1. Define a Pydantic Task model with at least a title, a completed flag, and one more field of your choice.
  2. Connect to a MongoDB database (local, Docker, or a free Atlas cluster) using Motor.
  3. Build full CRUD endpoints, POST /tasks, GET /tasks, GET /tasks/{id}, PUT /tasks/{id}, and DELETE /tasks/{id}.
  4. Return a proper 404 when a requested task doesn't exist.
  5. Confirm your endpoints work using the automatic docs at /docs.

Stretch goals

  • Add a query parameter to filter tasks by done status.
  • Add pagination with skip/limit query parameters.
  • Add a second collection (e.g. users or projects) with a relationship to tasks.

Submit your repository link below when you are done, an instructor will review it before you can mark this lesson complete. Good luck! 🚀

This lesson ends in a project. Build it on your own machine, there's nowhere to submit it here, but the brief above is everything you need.