This is a RESTful API built with FastAPI (versionDocumentation 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.
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 tolocalhost by default. The port depends on how you start the application:
| Mode | Base URL |
|---|---|
| Default | http://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.
All Endpoints
The table below lists every route registered across all three routers.| Method | Path | Description | Tag |
|---|---|---|---|
GET | / | Welcome message | General |
GET | /users/ | List all users | User |
GET | /users/{id} | Get user by ID | User |
POST | /users/ | Create a user | User |
PUT | /users/{id} | Update a user | User |
DELETE | /users/{id} | Delete a user | User |
GET | /tasks/ | List all tasks | Task |
GET | /tasks/{id} | Get task by ID | Task |
POST | /tasks/ | Create a task | Task |
PUT | /tasks/{id} | Update a task | Task |
DELETE | /tasks/{id} | Delete a task | Task |
Request & Response Format
All request bodies must be sent as JSON with theContent-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:
User model shape accepted and returned by the /users/ endpoints is:
Task model shape accepted and returned by the /tasks/ endpoints is:
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 raisesHTTPException 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:
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.