|
1 |
| -# ποΈ Flask MongoDB Product API |
| 1 | +# NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD |
2 | 2 |
|
3 |
| -A lightweight and scalable RESTful API built with **Flask** and **MongoDB**, designed for managing products using clean CRUD operations. Ideal for learning backend architecture, REST principles, and NoSQL integration. |
| 3 | +  |
4 | 4 |
|
5 |
| ---- |
| 5 | +## Overview |
6 | 6 |
|
7 |
| -## π Table of Contents |
| 7 | +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. |
8 | 8 |
|
9 |
| -1. [Features](#-features) |
10 |
| -2. [Tech Stack](#-tech-stack) |
11 |
| -3. [Getting Started](#-getting-started) |
12 |
| -4. [API Endpoints](#-api-endpoints) |
13 |
| -5. [Project Structure](#-project-structure) |
14 |
| -6. [Contributing](#-contributing) |
15 |
| -7. [Author](#-author) |
| 9 | +### Features |
16 | 10 |
|
17 |
| ---- |
| 11 | +- **CRUD Operations**: Implemented cleanly and efficiently. |
| 12 | +- **Modular Structure**: Easy to maintain and expand. |
| 13 | +- **Query/Path Parameter Support**: Flexible API for various needs. |
| 14 | +- **Professional Backend Architecture**: Suitable for production use. |
18 | 15 |
|
19 |
| -## π Features |
| 16 | +### Technologies Used |
20 | 17 |
|
21 |
| -- β
Full REST API using Flask Blueprint |
22 |
| -- β
CRUD operations with MongoDB (via PyMongo) |
23 |
| -- β
Handles both query and path parameters |
24 |
| -- β
ObjectId and numeric ID support |
25 |
| -- β
Modular code: routes, models, DB connection separated |
26 |
| -- β
Environment-based config with `.env` |
27 |
| -- β
Built-in validation and error handling |
| 18 | +- **Flask**: A lightweight WSGI web application framework. |
| 19 | +- **MongoDB**: A NoSQL database for storing product data. |
| 20 | +- **PyMongo**: A Python driver for MongoDB. |
| 21 | +- **RESTful Principles**: Ensures the API is stateless and scalable. |
28 | 22 |
|
29 |
| ---- |
| 23 | +### Topics |
30 | 24 |
|
31 |
| -## π§° Tech Stack |
| 25 | +This repository covers a variety of topics, including: |
32 | 26 |
|
33 |
| -- **Language:** Python 3.10+ |
34 |
| -- **Framework:** Flask |
35 |
| -- **Database:** MongoDB (NoSQL) |
36 |
| -- **Driver:** PyMongo |
37 |
| -- **Environment Config:** `python-dotenv` |
38 |
| -- **Testing:** Postman / Curl |
39 |
| -- **Tooling:** Git, VSCode, pip |
| 27 | +- backend-api |
| 28 | +- crud |
| 29 | +- crud-api |
| 30 | +- crud-application |
| 31 | +- crud-operation |
| 32 | +- database |
| 33 | +- flask-api |
| 34 | +- flask-application |
| 35 | +- flask-restful |
| 36 | +- mongodb |
| 37 | +- mongodb-atlas |
| 38 | +- nosql-database |
| 39 | +- queryparameters |
| 40 | +- rest-api |
| 41 | +- routing |
40 | 42 |
|
41 |
| ---- |
| 43 | +## Getting Started |
| 44 | + |
| 45 | +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: |
| 46 | + |
| 47 | +### Prerequisites |
| 48 | + |
| 49 | +1. **Python**: Make sure you have Python 3.x installed. You can download it from [python.org](https://www.python.org/downloads/). |
| 50 | +2. **MongoDB**: Install MongoDB. You can find the installation guide [here](https://docs.mongodb.com/manual/installation/). |
| 51 | +3. **Virtual Environment**: It's recommended to create a virtual environment for your project. |
| 52 | + |
| 53 | +### Installation |
| 54 | + |
| 55 | +1. **Clone the Repository**: |
| 56 | + |
| 57 | + ```bash |
| 58 | + git clone https://github.com/Lehuuuuuuuu/NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD.git |
| 59 | + cd NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD |
| 60 | + ``` |
| 61 | + |
| 62 | +2. **Set Up a Virtual Environment**: |
| 63 | + |
| 64 | + ```bash |
| 65 | + python -m venv venv |
| 66 | + source venv/bin/activate # On Windows use `venv\Scripts\activate` |
| 67 | + ``` |
| 68 | + |
| 69 | +3. **Install Dependencies**: |
| 70 | + |
| 71 | + ```bash |
| 72 | + pip install -r requirements.txt |
| 73 | + ``` |
| 74 | + |
| 75 | +### Configuration |
| 76 | + |
| 77 | +1. **MongoDB Connection**: Update the MongoDB connection string in the configuration file. You can use MongoDB Atlas or a local MongoDB instance. |
| 78 | + |
| 79 | +2. **Environment Variables**: Set any necessary environment variables, such as your database URI. |
| 80 | + |
| 81 | +### Running the Application |
| 82 | + |
| 83 | +To run the application, execute the following command: |
| 84 | + |
| 85 | +```bash |
| 86 | +flask run |
| 87 | +``` |
| 88 | + |
| 89 | +Your API will be available at `http://127.0.0.1:5000`. |
| 90 | + |
| 91 | +### API Endpoints |
| 92 | + |
| 93 | +The API provides several endpoints for managing product data: |
| 94 | + |
| 95 | +- **Create a Product**: `POST /products` |
| 96 | +- **Get All Products**: `GET /products` |
| 97 | +- **Get a Product by ID**: `GET /products/<id>` |
| 98 | +- **Update a Product**: `PUT /products/<id>` |
| 99 | +- **Delete a Product**: `DELETE /products/<id>` |
| 100 | + |
| 101 | +### Example Usage |
| 102 | + |
| 103 | +You can use tools like Postman or curl to interact with the API. Here are some example requests: |
| 104 | + |
| 105 | +1. **Create a Product**: |
| 106 | + |
| 107 | + ```bash |
| 108 | + curl -X POST http://127.0.0.1:5000/products -H "Content-Type: application/json" -d '{"name": "Product1", "price": 100}' |
| 109 | + ``` |
| 110 | + |
| 111 | +2. **Get All Products**: |
| 112 | + |
| 113 | + ```bash |
| 114 | + curl http://127.0.0.1:5000/products |
| 115 | + ``` |
42 | 116 |
|
43 |
| -## βοΈ Getting Started |
| 117 | +3. **Get a Product by ID**: |
| 118 | + |
| 119 | + ```bash |
| 120 | + curl http://127.0.0.1:5000/products/<id> |
| 121 | + ``` |
| 122 | + |
| 123 | +4. **Update a Product**: |
| 124 | + |
| 125 | + ```bash |
| 126 | + curl -X PUT http://127.0.0.1:5000/products/<id> -H "Content-Type: application/json" -d '{"name": "Updated Product", "price": 150}' |
| 127 | + ``` |
| 128 | + |
| 129 | +5. **Delete a Product**: |
| 130 | + |
| 131 | + ```bash |
| 132 | + curl -X DELETE http://127.0.0.1:5000/products/<id> |
| 133 | + ``` |
| 134 | + |
| 135 | +### Testing |
| 136 | + |
| 137 | +You can run tests using the built-in test suite. Make sure to have your virtual environment activated, then run: |
44 | 138 |
|
45 |
| -### 1οΈβ£ Clone the Repository |
46 | 139 | ```bash
|
47 |
| -git clone https://github.com/your-username/flask-mongo-api.git |
48 |
| -cd flask-mongo-api |
| 140 | +pytest |
49 | 141 | ```
|
50 | 142 |
|
51 |
| -## 2οΈβ£ Create Virtual Environment |
| 143 | +### Documentation |
| 144 | + |
| 145 | +For detailed API documentation, please refer to the [Releases section](https://github.com/Lehuuuuuuuu/NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD/releases). Here you can find the latest updates, features, and changes. |
52 | 146 |
|
53 |
| -python -m venv venv |
54 |
| -source venv/bin/activate # Windows: venv\Scripts\activate |
| 147 | +### Contribution |
55 | 148 |
|
| 149 | +Contributions are welcome! If you would like to contribute to this project, please follow these steps: |
56 | 150 |
|
57 |
| -## π API Endpoints |
| 151 | +1. Fork the repository. |
| 152 | +2. Create a new branch for your feature or bug fix. |
| 153 | +3. Make your changes. |
| 154 | +4. Submit a pull request. |
58 | 155 |
|
59 |
| -- π Get All Products |
60 |
| -- π Get Product by ID (Path) |
61 |
| -- β Create Product (Query Params) |
62 |
| -- π Update Entire Product (PUT - Query Params) |
63 |
| -- π©Ή Partial Update (PATCH - Query Params) |
64 |
| -- β Delete Product (Path Param) |
| 156 | +### License |
65 | 157 |
|
| 158 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
66 | 159 |
|
67 |
| -## π Project Structure |
| 160 | +### Acknowledgments |
68 | 161 |
|
69 |
| - |
| 162 | +- **Flask Documentation**: [Flask](https://flask.palletsprojects.com/) |
| 163 | +- **MongoDB Documentation**: [MongoDB](https://docs.mongodb.com/) |
| 164 | +- **PyMongo Documentation**: [PyMongo](https://pymongo.readthedocs.io/) |
70 | 165 |
|
| 166 | +### Contact |
71 | 167 |
|
72 |
| -## π€ Contributing |
73 |
| -### Pull requests are welcome! |
74 |
| -### To contribute: |
| 168 | +For any inquiries, please reach out to the repository owner via GitHub. |
75 | 169 |
|
76 |
| -- Fork the repository |
77 |
| -- Create a new branch (git checkout -b feature/your-feature) |
78 |
| -- Commit your changes (git commit -m 'Add new feature') |
79 |
| -- Push the branch (git push origin feature/your-feature) |
80 |
| -- Open a Pull Request π |
| 170 | +### Links |
81 | 171 |
|
| 172 | +- Visit the [Releases section](https://github.com/Lehuuuuuuuu/NOSQL-MONGO-FLASK-PYMONGO-RESTAPI-METHODS-CRUD/releases) for downloadable files and execution instructions. |
| 173 | + |
| 174 | +--- |
82 | 175 |
|
83 |
| -### π¨βπ» Author |
84 |
| -Sikandar Khan |
85 |
| -π§ sikandaraidev@gmail.com |
86 |
| -π LinkedIn: https://www.linkedin.com/in/sikandaraidev/ |
87 |
| -πΌ AI Engineer | Backend Developer |
| 176 | +Feel free to explore the code, make improvements, and enjoy building your applications with this robust REST API! |
0 commit comments