Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tutosrive/fastapi-CRUD-MongoDB/llms.txt

Use this file to discover all available pages before exploring further.

This is a RESTful API built with FastAPI (version 2025.0.1.0) that provides full CRUD endpoints for two resources — Users and Tasks — backed by a MongoDB database. All request and response bodies use JSON. The API is structured around three routers (General, User, and Task) and is self-documenting through FastAPI’s built-in OpenAPI support.

Base URL

The server binds to localhost by default. The port depends on how you start the application:
ModeBase URL
Defaulthttp://localhost:8000
Dev mode (--port 5000)http://localhost:5000
Both URLs above are local development addresses. The API is not deployed to a remote host — you must run the FastAPI server on your own machine to use these endpoints.

Interactive Docs

FastAPI automatically generates interactive API documentation from the OpenAPI schema. Once the server is running, you can explore all endpoints directly in your browser:
  • Swagger UI/docs: A full interactive playground where you can inspect schemas, fill in request bodies, and execute live requests.
  • ReDoc/redoc: A clean, read-only reference layout that displays all endpoints and schemas in a single scrollable page.
No setup is required — both interfaces are served automatically by FastAPI.

All Endpoints

The table below lists every route registered across all three routers.
MethodPathDescriptionTag
GET/Welcome messageGeneral
GET/users/List all usersUser
GET/users/{id}Get user by IDUser
POST/users/Create a userUser
PUT/users/{id}Update a userUser
DELETE/users/{id}Delete a userUser
GET/tasks/List all tasksTask
GET/tasks/{id}Get task by IDTask
POST/tasks/Create a taskTask
PUT/tasks/{id}Update a taskTask
DELETE/tasks/{id}Delete a taskTask

Request & Response Format

All request bodies must be sent as JSON with the Content-Type: application/json header. All successful responses are returned as JSON. Resource IDs (the id field on both User and Task objects) are MongoDB ObjectId strings — 24-character lowercase hexadecimal values, for example:
{
  "id": "6643f1a2b4e3c2d1a0f9e817"
}
The User model shape accepted and returned by the /users/ endpoints is:
{
  "id": "6643f1a2b4e3c2d1a0f9e817",
  "name": "Jane Doe",
  "age": 30,
  "email": "jane@example.com"
}
The Task model shape accepted and returned by the /tasks/ endpoints is:
{
  "id": "6643f1a2b4e3c2d1a0f9e818",
  "title": "Write documentation",
  "description": "Document all API endpoints",
  "completed": false,
  "created_by": "6643f1a2b4e3c2d1a0f9e817"
}
For PUT /tasks/{id}, all fields are optional — only the fields you include in the body will be applied to the update.

Error Responses

The API raises HTTPException responses in two scenarios: when a requested resource cannot be found, and when a resource cannot be created. Errors follow FastAPI’s default error envelope with a detail key. 404 Not Found — returned when no document matching the given ID exists in MongoDB:
{"detail": "User Not Found!"}
{"detail": "Task Not Found!"}
400 Bad Request — returned when a document fails to be inserted into the database:
{"detail": "The user can't bee added!"}
{"detail": "The task can't bee added!"}
The "bee" typo in both 400 error messages (can't bee added) is present in the source code as-is. If you are consuming this API programmatically, match against the detail string exactly or check only the HTTP status code.

Explore by Resource

User Endpoints

Browse all CRUD operations for the User resource — list, retrieve, create, update, and delete users.

Task Endpoints

Browse all CRUD operations for the Task resource — list, retrieve, create, update, and delete tasks.

Build docs developers (and LLMs) love