Skip to content

This project provides a fully functional API to manage cafes, supporting CRUD operations (Create, Read, Update, Delete). Users can fetch all cafes, search by location, add new cafes, update coffee prices, and delete entries with secure API key validation.

Notifications You must be signed in to change notification settings

ayushi-gajendra/Cafe_and_Wifi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

β˜• Cafe and Wifi - Cafe API with Flask & SQLAlchemy

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.


πŸ”₯ Features

  • 🏠 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)

πŸ› οΈ Tech Stack

  • Python
  • Flask
  • Flask-SQLAlchemy (with SQLAlchemy 2.0-style ORM)
  • SQLite
  • REST principles
  • JSON responses

πŸ“ Project Structure

cafe-api/
β”œβ”€β”€ instance/
β”‚   └── cafes.db
β”œβ”€β”€ templates/
β”‚   └── index.html
β”œβ”€β”€ main.py
└── README.md

πŸš€ Getting Started

  1. Clone this repo:

    git clone https://github.com/ayushi-gajendra/Cafe_and_Wifi.git
    cd Cafe_and_Wifi
  2. Install dependencies:

    pip install Flask Flask-SQLAlchemy
  3. Run the app:

    python main.py
  4. Open in browser:

    http://127.0.0.1:5000/
    

πŸ”’ API Key (for Delete)

  • To use the DELETE endpoint, you must provide the query parameter:
    api-key=TopSecretAPIKey
    

πŸ’‘ Sample JSON Response

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

πŸ§ͺ Testing the API

Use tools like:

  • Postman
  • curl in terminal
  • Browser for simple GET routes

About

This project provides a fully functional API to manage cafes, supporting CRUD operations (Create, Read, Update, Delete). Users can fetch all cafes, search by location, add new cafes, update coffee prices, and delete entries with secure API key validation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published