This project is a simple REST API that simulates a coffee shop ordering system. It is designed to teach non-technical users how APIs work using easy-to-follow commands.
- 📋 View Menu – See available drinks and sizes
- ☕ Place an Order – Order a coffee with your name
- 📜 View Orders – List all placed orders
- ✏️ Update an Order – Modify your drink or size
- ❌ Cancel an Order – Remove an order
git clone https://github.com/dholdaway/CoffeeShopAPI.git
cd CoffeeShopAPI
Ensure you have Python 3+ installed, then install Flask:
pip install flask
Start the Flask server:
python app.py
🚀 The API is now running at http://127.0.0.1:5000
Retrieves all available drinks and sizes.
curl -X GET http://127.0.0.1:5000/menu
✅ Example Response:
{
"coffee": {
"Espresso": { "small": 2.50, "medium": 3.00, "large": 3.50 },
"Latte": { "small": 3.50, "medium": 4.00, "large": 4.50 }
},
"tea": {
"Green Tea": { "small": 2.00, "medium": 2.50, "large": 3.00 }
}
}
Submit an order by providing your name, drink, and size.
curl -X POST http://127.0.0.1:5000/order \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "drink": "Latte", "size": "medium"}'
✅ Example Response:
{
"message": "Order placed",
"order_id": 1,
"details": {
"name": "Alice",
"drink": "Latte",
"size": "medium",
"price": 4.00
}
}
Lists all orders placed by customers.
curl -X GET http://127.0.0.1:5000/orders
✅ Example Response:
{
"1": { "name": "Alice", "drink": "Latte", "size": "medium", "price": 4.00 }
}
Modify an existing order by changing the drink or size.
curl -X PUT http://127.0.0.1:5000/order/1 \
-H "Content-Type: application/json" \
-d '{"drink": "Cappuccino", "size": "large"}'
✅ Example Response:
{
"message": "Order updated",
"order_id": 1,
"details": {
"name": "Alice",
"drink": "Cappuccino",
"size": "large",
"price": 4.50
}
}
Removes an order by order ID.
curl -X DELETE http://127.0.0.1:5000/order/1
✅ Example Response:
{
"message": "Order cancelled",
"order_id": 1
}
- APIs allow applications to communicate
- HTTP methods:
- GET (Retrieve data)
- POST (Create data)
- PUT (Update data)
- DELETE (Remove data)
- JSON format is used to exchange data between client and server
Issue | Solution |
---|---|
ModuleNotFoundError: No module named 'flask' |
Run pip install flask |
API not starting? | Ensure app.py is running: python app.py |
curl: command not found |
Install curl: sudo apt install curl or use Postman |
- Feel free to submit issues or pull requests.
- Improve the project by adding a frontend, authentication, or a leaderboard.
🚀 Enjoy learning APIs with the Coffee Shop Demo! ☕🎉