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