volfpeter /
motorhead
Async MongoDB with vanilla Pydantic v2+ - made easy.
64/100 healthLoading repository data…
vineet416 / repository
FastAPI MongoDB API - A modern, async REST API built with FastAPI and MongoDB (Motor driver) that provides full CRUD operations. Features automatic data validation with Pydantic, interactive API documentation via Swagger UI, and production deployment on Render. Perfect for learning FastAPI or as a starter template for MongoDB-backed APIs.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A simple yet powerful REST API built with FastAPI and MongoDB that provides CRUD (Create, Read, Update, Delete) operations for managing user data.
The API is deployed and accessible at: https://fastapi-mongodb-api-5q42.onrender.com/docs
Before you begin, ensure you have the following installed:
Selected from shared topics, language and repository description—not editorial ratings.
volfpeter /
Async MongoDB with vanilla Pydantic v2+ - made easy.
64/100 healthvolfpeter /
Collection of async utilities for working with MongoDB and conveniently creating performant APIs with async web frameworks such a FastAPI
22/100 healthgit clone https://github.com/vineet416/fastapi_mongodb_api.git
cd fastapi_mongodb_api
On Windows:
python -m venv apienv
apienv\Scripts\activate
On macOS/Linux:
python3 -m venv apienv
source apienv/bin/activate
pip install -r requirements.txt
.env FileCreate a .env file in the root directory of the project:
echo. > .env
Open the .env file and add your MongoDB connection string:
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority
To get your MongoDB URI:
<username> and <password> with your credentialsStart the FastAPI server using Uvicorn:
uvicorn main:app --reload
The API will be available at:
| Method | Endpoint | Description | Parameters |
|---|---|---|---|
| GET | / | Home route - Welcome message | None |
| GET | /api/getdata | Retrieve all records | None |
| POST | /api/insert | Insert a new record | Request Body: JSON object |
| PUT | /api/fullupdate | Full update of a record (all fields required) | Query: id, Request Body: JSON object |
| PATCH | /api/partialupdate | Partial update of a record (only specified fields) | Query: id, Request Body: JSON object |
| DELETE | /api/delete | Delete a record | Query: id |
{
"name": "string",
"phone": 0,
"city": "string",
"course": "string"
}
Endpoint: GET /
Response:
{
"message": "Welcome to the FastAPI MongoDB CRUD API. Visit /docs for API documentation."
}
Endpoint: GET /api/getdata
Response:
[
{
"id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"phone": 1234567890,
"city": "New York",
"course": "Computer Science"
}
]
Endpoint: POST /api/insert
Request Body:
{
"name": "John Doe",
"phone": 1234567890,
"city": "New York",
"course": "Computer Science"
}
Response:
{
"message": "Data inserted successfully",
"id": "507f1f77bcf86cd799439011"
}
Endpoint: PUT /api/fullupdate?id=507f1f77bcf86cd799439011
Description: Updates all fields of a record. All fields must be provided.
Request Body:
{
"name": "John Doe",
"phone": 9876543210,
"city": "Los Angeles",
"course": "Data Science"
}
Response:
{
"message": "Data fully updated successfully"
}
Endpoint: PATCH /api/partialupdate?id=507f1f77bcf86cd799439011
Description: Updates only the specified fields. You can update one or more fields without providing all fields.
Request Body (update single field):
{
"city": "Mumbai"
}
Request Body (update multiple fields):
{
"city": "Mumbai",
"phone": 9876543210
}
Response:
{
"message": "Data partially updated successfully"
}
Endpoint: DELETE /api/delete?id=507f1f77bcf86cd799439011
Response:
{
"message": "Data deleted successfully"
}
fastapi_mongodb_api/
│
├── main.py # Main application file with API endpoints
├── requirements.txt # Python dependencies
├── .env # Environment variables (not in repo)
├── README.md # Project documentation
└── apienv/ # Virtual environment (not in repo)
This project is deployed on Render. To deploy your own instance:
Build Command:
pip install -r requirements.txt
Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT
Get All Data:
curl -X GET "http://127.0.0.1:8000/api/getdata"
Insert Data:
curl -X POST "http://127.0.0.1:8000/api/insert" -H "Content-Type: application/json" -d "{\"name\":\"Jane Smith\",\"phone\":5551234567,\"city\":\"Chicago\",\"course\":\"AI/ML\"}"
Full Update:
curl -X PUT "http://127.0.0.1:8000/api/fullupdate?id=YOUR_ID_HERE" -H "Content-Type: application/json" -d "{\"name\":\"Jane Smith\",\"phone\":9999999999,\"city\":\"Mumbai\",\"course\":\"Data Science\"}"
Partial Update:
curl -X PATCH "http://127.0.0.1:8000/api/partialupdate?id=YOUR_ID_HERE" -H "Content-Type: application/json" -d "{\"city\":\"Delhi\"}"
Delete Data:
curl -X DELETE "http://127.0.0.1:8000/api/delete?id=YOUR_ID_HERE"
import requests
base_url = "http://127.0.0.1:8000"
# Get all data
response = requests.get(f"{base_url}/api/getdata")
print(response.json())
# Insert data
response = requests.post(
f"{base_url}/api/insert",
json={
"name": "Jane Smith",
"phone": 5551234567,
"city": "Chicago",
"course": "AI/ML"
}
)
print(response.json())
inserted_id = response.json()["id"]
# Full update (all fields required)
response = requests.put(
f"{base_url}/api/fullupdate",
params={"id": inserted_id},
json={
"name": "Jane Smith",
"phone": 9999999999,
"city": "Mumbai",
"course": "Data Science"
}
)
print(response.json())
# Partial update (only specified fields)
response = requests.patch(
f"{base_url}/api/partialupdate",
params={"id": inserted_id},
json={
"city": "Delhi"
}
)
print(response.json())
# Delete data
response = requests.delete(
f"{base_url}/api/delete",
params={"id": inserted_id}
)
print(response.json())
Contributions are welcome! Please feel free to submit a Pull Request.
Vineet Patel
If you have any questions or need help, feel free to reach out or open an issue on GitHub.
⭐ Star this repository if you find it helpful!
jjaramillo34 /
Repo CRUD Tutorial with Fast API & MongoDB
rafaski /
A currency converter API built with FastAPI, mongoDB, redis and httpx
42/100 healthMartinsMessias /
CRUD API assíncrona com FastAPI e MongoDB. Usando o pacote Motor para interagir com o MongoDB de forma assíncrona. Implementado com testes com TestClient e CI/CD no GitHub Actions com deploy no Heroku.
41/100 healthmaxsonferovante /
A Potiguar API é um serviço projetado para facilitar a consulta de infrações de veículos, subsídios e multas no Rio Grande do Norte.
41/100 health