This repository contains the backend code for the Online Shopping Web App. It provides the necessary APIs and functionalities to support the frontend of the application.
-
Clone the repository:
git clone cd online-shopping-web-app-backend
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Set up MongoDB:
- Install MongoDB and start the MongoDB service.
- Alternatively, you can use a cloud-based MongoDB service like MongoDB Atlas.
-
Create a
config.py
file for the configuration settings:# config.py class Config: MONGO_URI = "mongodb://localhost:27017/online-shopping-db"
To run the application, execute the following command:
python app.py
The server will be running on http://localhost:5000 by default. Use a tool like Postman to test the available APIs. API Endpoints Here are some example API endpoints you can use:
- URL: http://localhost:5000/items
- Method: POST
- Request Body:
{ "item_code": "I001", "description": "ASUS VIVOBOOK X512FA", "category": "Laptop", "description": "ASUS VIVO BOOK 15", "item_code": "I005", "price": 3500, "rating": 3.5, "stock": 50 }
- Response:
- Success Response:
{ "success": True }
- Error Response:
{ "error": "Item already exists" }
- URL: http://localhost:5000/items
- Method: GET
- Response:
- Success Response:
{ "items": [ { "category": "Laptop", "description": "ASUS VIVO BOOK 15", "item_code": "I005", "price": 3500, "rating": 3.5, "stock": 50 }, { "category": "Laptop", "description": "ASUS VIVO BOOK 15", "item_code": "I005", "price": 3500, "rating": 3.5, "stock": 50 } ] }
- Error Response:
{ "error": "No items found" }
- URL: http://localhost:5000/items/I001
- Method: GET
- Response:
- Success Response:
{ "category": "Laptop", "description": "ASUS VIVO BOOK 15", "item_code": "I005", "price": 3500, "rating": 3.5, "stock": 50 }
- Error Response:
{ "error": "Item not found" }
- URL: http://localhost:5000/items/I001
- Method: PUT
- Request Body:
{ "price": 4000, "stock": 40 }
- Response:
- Success Response:
{ "success": True }
- Error Response:
{ "error": "Item not found" }
- URL: http://localhost:5000/items/I001
- Method: DELETE
- Response:
- Success Response:
{ "success": True }
- Error Response:
{ "error": "Item not found" }
The application requires the following dependencies:
Flask==1.1.2
Flask-PyMongo==2.3.0
This project is licensed under the MIT License - see the LICENSE file for details.