Skip to content

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

 
 
 

Contributors