Welcome to the NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD repository! This project offers a fully functional REST API built with Flask and MongoDB. It is designed for managing product data with clean CRUD (Create, Read, Update, Delete) operations. The architecture is modular and supports both query and path parameters, making it suitable for real-world applications.
- CRUD Operations: Implemented cleanly and efficiently.
- Modular Structure: Easy to maintain and expand.
- Query/Path Parameter Support: Flexible API for various needs.
- Professional Backend Architecture: Suitable for production use.
- Flask: A lightweight WSGI web application framework.
- MongoDB: A NoSQL database for storing product data.
- PyMongo: A Python driver for MongoDB.
- RESTful Principles: Ensures the API is stateless and scalable.
This repository covers a variety of topics, including:
- backend-api
- crud
- crud-api
- crud-application
- crud-operation
- database
- flask-api
- flask-application
- flask-restful
- mongodb
- mongodb-atlas
- nosql-database
- queryparameters
- rest-api
- routing
To get started with this project, you will need to have Python and MongoDB installed on your machine. Follow these steps to set up the project:
- Python: Make sure you have Python 3.x installed. You can download it from python.org.
- MongoDB: Install MongoDB. You can find the installation guide here.
- Virtual Environment: It's recommended to create a virtual environment for your project.
-
Clone the Repository:
git clone https://github.com/Lehuuuuuuuu/NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD.git cd NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD
-
Set Up a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
MongoDB Connection: Update the MongoDB connection string in the configuration file. You can use MongoDB Atlas or a local MongoDB instance.
-
Environment Variables: Set any necessary environment variables, such as your database URI.
To run the application, execute the following command:
flask run
Your API will be available at http://127.0.0.1:5000
.
The API provides several endpoints for managing product data:
- Create a Product:
POST /products
- Get All Products:
GET /products
- Get a Product by ID:
GET /products/<id>
- Update a Product:
PUT /products/<id>
- Delete a Product:
DELETE /products/<id>
You can use tools like Postman or curl to interact with the API. Here are some example requests:
-
Create a Product:
curl -X POST http://127.0.0.1:5000/products -H "Content-Type: application/json" -d '{"name": "Product1", "price": 100}'
-
Get All Products:
curl http://127.0.0.1:5000/products
-
Get a Product by ID:
curl http://127.0.0.1:5000/products/<id>
-
Update a Product:
curl -X PUT http://127.0.0.1:5000/products/<id> -H "Content-Type: application/json" -d '{"name": "Updated Product", "price": 150}'
-
Delete a Product:
curl -X DELETE http://127.0.0.1:5000/products/<id>
You can run tests using the built-in test suite. Make sure to have your virtual environment activated, then run:
pytest
For detailed API documentation, please refer to the Releases section. Here you can find the latest updates, features, and changes.
Contributions are welcome! If you would like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any inquiries, please reach out to the repository owner via GitHub.
- Visit the Releases section for downloadable files and execution instructions.
Feel free to explore the code, make improvements, and enjoy building your applications with this robust REST API!