This is a simple Flask-based API that provides information about cafes, allows the addition, updating, and deletion of cafe records in a database, and includes functionality to get random cafes and search by location.
- Python 3.x
- Flask
- Flask-SQLAlchemy
- SQLAlchemy
-
Clone the repository:
git clone https://github.com/MostafaHima/Cafe-API-Flask-Application.git cd Cafe-API-Flask-Application -
Install the required packages using pip:
pip install -r requirements.txt
-
Set up the database by running the Flask application:
flask run python main.py
The home page of the application is a simple interface that can be accessed by visiting http://localhost:5000 after running the Flask application. It renders an index.html template.
This endpoint returns a random cafe from the database.
Response:
200 OKwith a JSON object containing the cafe details.
This endpoint retrieves all cafes from the database and returns them as a JSON array.
Response:
200 OKwith a JSON object containing all cafe records.
This endpoint searches for cafes in a specific location.
Example Request:
/search/London
Response:
200 OKwith a JSON object containing the cafe details if found.404 Not Foundif no cafes are found in that location.
This endpoint allows adding a new cafe record to the database.
Request Body (form-data):
name: Name of the cafemap_url: URL for the map location of the cafeimg_url: Image URL of the cafelocation: Location of the cafehas_sockets: Boolean (True/False) indicating if the cafe has power socketshas_toilet: Boolean (True/False) indicating if the cafe has toiletshas_wifi: Boolean (True/False) indicating if the cafe has Wi-Fican_take_calls: Boolean (True/False) indicating if the cafe allows taking callsseats: Seating capacity of the cafecoffee_price: Price of a coffee at the cafe
Response:
200 OKwith a success message.
This endpoint allows updating the coffee price for a specific cafe by its id.
Request Parameters:
new_price: The new price for the coffee.
Response:
200 OKwith a success message.404 Not Foundif the cafe is not found by the providedid.
This endpoint allows deleting a cafe record by its id. Requires an API key.
Request Parameters:
api-key: An API key for authentication.
Response:
200 OKwith a success message if the cafe is deleted.403 Forbiddenif the API key is incorrect.404 Not Foundif the cafe with the providediddoes not exist.