Skip to content

Distributed backend CRUD application using Flask and MongoDB — ideal for scalable, modular API development.

Notifications You must be signed in to change notification settings

ChetanFTW/crud-api-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask API with MongoDB, Docker, and Optimized Performance

A simple Flask REST API with MongoDB for basic CRUD operations on users.


Prerequisites

  • Docker and Docker Compose installed on your machine.
  • If you have a local MongoDB instance running, stop it to avoid port conflicts.

Stop local MongoDB (Linux/macOS)

sudo systemctl stop mongod

# or alternatively

ps aux | grep mongod

Setup & Run

Clone the repository:

git clone https://github.com/yourusername/flask-mongo-crud.git
cd flask-mongo-crud

Bring down any running containers (if any) => Build and start the Flask app with MongoDB:

docker-compose down
docker-compose up --build

Your API will be accessible at: http://localhost:5000 (or http://172.21.0.3:5000 if using a specific Docker network)

API Endpoints

| Method | Endpoint      | Description             |
| ------ | ------------- | ----------------------- |
| GET    | `/users`      | List all users          |
| GET    | `/users/<id>` | Get a user by ID        |
| POST   | `/users`      | Create a new user       |
| PUT    | `/users/<id>` | Update an existing user |
| DELETE | `/users/<id>` | Delete a user by ID     |

Example Usage (with curl or Postman) => Create a user:

curl -X POST http://localhost:5000/users \
     -H "Content-Type: application/json" \
     -d '{"name": "John Doe", "email": "[email protected]", "password": "secret123"}'

Get all users:

curl -X GET http://localhost:5000/users

Update a User (PUT) Replace with the actual user ID:

curl -X PUT http://localhost:5000/users/<id> \
     -H "Content-Type: application/json" \
     -d '{"name": "Updated Name", "email": "[email protected]", "password": "newpassword123"}'

Delete a User (DELETE) Replace with the actual user ID:

curl -X DELETE http://localhost:5000/users/<id>

If you'd like, I can also generate a downloadable README.md file for you. Would you want that?

About

Distributed backend CRUD application using Flask and MongoDB — ideal for scalable, modular API development.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •