This project provides a simple CRUD API for managing products using Flask.
-
Install the required packages:
python3 -m pip install flask flask_cors
-
Run the app:
python3 products.py
-
URL:
/products
-
Method:
GET
-
Description: Returns a list of all products.
curl http://localhost:5000/products
-
URL:
/products/{id}
-
Method:
GET
-
Description: Returns a product based on the product ID.
curl http://localhost:5000/products/144
-
URL:
/products
-
Method:
POST
-
Description: Adds a new product to the list.
curl -X POST -H "Content-Type: application/json" \ -d '{"id": 145, "name": "Pen", "price": 2.5}' \ http://localhost:5000/products
-
URL:
/products/{id}
-
Method:
PUT
-
Description: Updates an existing product based on the product ID.
curl -X PUT -H "Content-Type: application/json" \ -d '{"name": "Updated Pen", "price": 3.0}' \ http://localhost:5000/products/145
-
URL:
/products/{id}
-
Method:
DELETE
-
Description: Deletes a product based on the product ID.
curl -X DELETE http://localhost:5000/products/145
You can test the API using the provided curl
commands or any API testing tool like Postman.
The API is documented using Swagger. You can find the Swagger JSON file in the static
directory.