A full-featured RESTful API built with Flask and SQLAlchemy to manage a collection of cafes. You can retrieve random cafes, search by location, add new entries, update coffee prices, and delete cafes — all with proper HTTP methods.
- 🏠
GET /– Home route (renders basic HTML) - 🎲
GET /random– Get a random cafe - 📚
GET /all– Retrieve all cafes - 🔍
GET /search?loc=LOCATION– Search cafes by location - ➕
POST /add– Add a new cafe via form data - ✏️
PATCH /update-price/<cafe_id>?new_price=₹PRICE– Update coffee price - ❌
DELETE /report-closed/<cafe_id>?api-key=TopSecretAPIKey– Delete cafe by ID (API key protected)
- Python
- Flask
- Flask-SQLAlchemy (with SQLAlchemy 2.0-style ORM)
- SQLite
- REST principles
- JSON responses
cafe-api/
├── instance/
│ └── cafes.db
├── templates/
│ └── index.html
├── main.py
└── README.md
-
Clone this repo:
git clone https://github.com/ayushi-gajendra/Cafe_and_Wifi.git cd Cafe_and_Wifi -
Install dependencies:
pip install Flask Flask-SQLAlchemy
-
Run the app:
python main.py
-
Open in browser:
http://127.0.0.1:5000/
- To use the DELETE endpoint, you must provide the query parameter:
api-key=TopSecretAPIKey
{
"cafe": {
"name": "Cafe Brew",
"map_url": "https://goo.gl/maps/sample",
"img_url": "https://images.unsplash.com/sample",
"location": "Delhi",
"seats": "20",
"has_toilet": true,
"has_wifi": true,
"has_sockets": false,
"can_take_calls": true,
"coffee_price": "₹150"
}
}Use tools like:
- Postman
curlin terminal- Browser for simple GET routes