← Back to Projects
MkViewer - Cafe API [Read-Only]
Initializing MkViewer...
README.md

Project 66 — Cafe API

README GENERATED BY AI

Overview

Project 66 is a Flask-based API that allows users to explore and manage cafe information. The API provides endpoints to list cafes, retrieve a random cafe, search by location, add new cafes, update coffee prices, and report closed cafes. Data is stored in a SQLite database using SQLAlchemy ORM.


Features

  • Retrieve all cafes (/all)
  • Get a random cafe (/random)
  • Search cafes by location (/search?loc=<location>)
  • Add new cafes (/add)
  • Update cafe coffee prices (/update-price/<id>)
  • Report a cafe as closed (/report-closed/<id> with API key)

Installation

  1. Clone the repository: ```bash git clone cd Project66 ````

  2. Install the required packages:

  3. On Windows:

bash python -m pip install -r requirements.txt

  • On MacOS:

bash pip3 install -r requirements.txt

  1. Run the Flask app:

bash python app.py

By default, the API runs on http://localhost:8000.


Database

The API uses SQLite (cafes.db) with the following table:

Cafe Table

| Column | Type | Description | | -------------- | ------ | ----------------------- | | id | int | Primary key | | name | string | Cafe name (unique) | | map_url | string | Google Maps link | | img_url | string | Image URL | | location | string | City or area | | seats | string | Number of seats | | has_toilet | bool | Toilet available | | has_wifi | bool | Wifi available | | has_sockets | bool | Power sockets available | | can_take_calls | bool | Phone calls allowed | | coffee_price | string | Coffee price |


API Endpoints

| Endpoint | Method | Description | | --------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | / | GET | Redirects to Postman documentation | | /all | GET | Returns all cafes in JSON format | | /random | GET | Returns a random cafe | | /search | GET | Search cafes by location: ?loc=<location> | | /add | POST | Add a new cafe with required query params: name, map_url, img_url, location, seats, optional: has_toilet, has_wifi, has_sockets, can_take_calls, coffee_price | | /update-price/<id> | PATCH | Update the coffee price of a cafe with given id | | /report-closed/<id> | DELETE | Delete a cafe record (requires api_key=TopSecretAPIKey) |


Usage Examples

Get a random cafe

bash GET http://localhost:8000/random

Search cafes in Peckham

bash GET http://localhost:8000/search?loc=Peckham

Add a new cafe

bash POST http://localhost:8000/add?name=Becks%20Cafe&map_url=https://maps.google.com/?q=Becks%20Cafe&img_url=<url>&location=Peckham&seats=20&has_wifi=1&has_toilet=1

Update coffee price

bash PATCH http://localhost:8000/update-price/1?new_price=$3.50

Report a cafe closed

bash DELETE http://localhost:8000/report-closed/1?api_key=TopSecretAPIKey


Notes

  • API follows REST principles with GET, POST, PATCH, and DELETE methods.
  • Data is returned in JSON format.
  • Requires TopSecretAPIKey for delete operations.
  • Flask app runs in debug mode on port 8000.

License

This project is for educational purposes.