Small practice project for a store API, created using Flask. Done following the "Flask REST API" section of the "REST APIs with Flask and Python in 2025 " course on Udemy.
The API allows users to:
- Create, retrieve, and delete stores (each store has a unique ID and name)
- Create, retrieve, update, and delete items (each item has a unique ID, name, price, and associated store_id)
- List all stores or all items
- Retrieve individual stores or items by ID
Prerequisites
- Python 3.10 or higher
- pip (Python package manager)
-
Create a virtual environment (optional, recommended)
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Copy the example environment file and update if needed:
cp .flaskenv.example .flaskenv
-
Run the Flask application
flask run
The API will be available at http://127.0.0.1:5000
Prerequisites
- Docker installed on your machine
-
Build the Docker image
docker build -t store-api . -
Run the container
docker run -dp 5000:5000 --name store-api-app store-api
The API will be available at http://localhost:5000
![NOTE] To run the container with autoload and debugging enabled, use the following command instead:
docker run -dp 5000:5000 -v "$(pwd):/app" --name store-api
GET /stores- Get all storesGET /stores/<store_id>- Get a specific store by IDPOST /stores- Create a new storeDELETE /stores/<store_id>- Delete a store
GET /items- Get all itemsGET /items/<item_id>- Get a specific item by IDPOST /items- Create a new itemPUT /items/<item_id>- Update an itemDELETE /items/<item_id>- Delete an item
GET /- Home endpoint
Create a new store:
curl -X POST http://localhost:5000/stores -H "Content-Type: application/json" -d '{"name": "My Store"}'Get all stores:
curl http://localhost:5000/storesCreate an item:
curl -X POST http://localhost:5000/items -H "Content-Type: application/json" -d '{"name": "Chair", "price": 19.99, "store_id": "<store_id>"}'Get all items:
curl http://localhost:5000/itemsUpdate an item:
curl -X PUT http://localhost:5000/items/<item_id> -H "Content-Type: application/json" -d '{"name": "Updated Chair", "price": 24.99}'Delete an item:
curl -X DELETE http://localhost:5000/items/<item_id>