Skip to content

dholdaway/WhatsAnApi

Repository files navigation

Coffee Shop API - Beginner's Guide to REST APIs

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.


🚀 Features

  • 📋 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

🔧 Installation & Setup

1️⃣ Clone the Repository

git clone https://github.com/dholdaway/CoffeeShopAPI.git
cd CoffeeShopAPI

2️⃣ Install Dependencies

Ensure you have Python 3+ installed, then install Flask:

pip install flask

3️⃣ Run the API

Start the Flask server:

python app.py

🚀 The API is now running at http://127.0.0.1:5000


📌 API Endpoints & Usage

📋 1. View the Menu (GET)

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 }
  }
}

2. Place an Order (POST)

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
  }
}

📜 3. View All Orders (GET)

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 }
}

✏️ 4. Update an Order (PUT)

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
  }
}

5. Cancel an Order (DELETE)

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
}

🎯 Key Learning Points

  • 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

🛠️ Troubleshooting

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

🎉 Contributing

  • 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! ☕🎉


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published