A RESTful API built with Flask, MongoDB, and Docker, supporting full CRUD operations for user management.
You can deploy it using Render, Railway, or Docker on VPS. Link goes here if hosted.
flask_mongo_crud/
β
βββ app/
β βββ __init__.py # App factory
β βββ config.py # App config (Mongo URI, etc.)
β βββ models/
β β βββ user.py # User model
β βββ routes/
β β βββ user_routes.py # API route definitions
β βββ schemas/
β β βββ user_schema.py # Marshmallow schema for validation
β βββ services/
β βββ user_service.py # Business logic for users
β
βββ .env # MongoDB URI (excluded via .gitignore)
βββ requirements.txt
βββ Dockerfile
βββ docker-compose.yml
βββ run.py # Entry point to start Flask app
- RESTful API using
Flask+Flask-RESTful - MongoDB database (via
Flask-PyMongo) - Input validation with
marshmallow - Secure password hashing using
Werkzeug - Dockerized for easy setup and deployment
- Modular architecture with services/models/routes
- Environment variable support with
python-dotenv
| Method | Endpoint | Description |
|---|---|---|
| GET | /users/ |
Get all users |
| GET | /users/<id> |
Get user by ID |
| POST | /users/ |
Create a new user |
| PUT | /users/<id> |
Update existing user |
| DELETE | /users/<id> |
Delete a user |
- Backend: Flask, Flask-PyMongo, Flask-RESTful, Marshmallow
- Database: MongoDB
- Security: Werkzeug (password hashing)
- Containerization: Docker, Docker Compose
- Testing: Pytest (optional)
- Environment Handling: python-dotenv
docker-compose up --buildVisit the API at: http://localhost:5050/users
# Create a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export MONGO_URI="your-mongodb-uri"
# Run the server
python run.py# Create a user
curl -X POST http://localhost:5050/users/ \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com","password":"secure123"}'
# Get all users
curl http://localhost:5050/users/
# Get single user
curl http://localhost:5050/users/<id>
# Update user
curl -X PUT http://localhost:5050/users/<id> \
-H "Content-Type: application/json" \
-d '{"name":"Jane Doe"}'
# Delete user
curl -X DELETE http://localhost:5050/users/<id>This project is licensed under the MIT License.