The Recipe API is a RESTful web service built with Flask and SQLAlchemy, allowing users to manage recipes, tags, and user accounts. It provides endpoints for creating, updating, deleting, and retrieving recipes, as well as authentication and authorization features for user management.
-
app.py: Main file containing the application's routes and controllers. -
models.py: Contains database models for the application. -
user.py: Handles user-related functionalities. -
recipe.py: Manages recipe creation, editing, and retrieval. -
reviews.py: Handles review functionalities for recipes. -
tags.py: Manages tagging functionalities for recipes and files.
-
Set up the database by running:
python models.py -
Start the application:
python app.py
User Authentication: Users can create accounts, log in, log out, and delete their accounts securely.
Recipe Management: Create, retrieve, update, and delete recipes. Each recipe includes details such as recipe name, ingredients, instructions, associated reviews and associated tags.
Tagging System: Recipes can be tagged with multiple categories for easy organization and filtering.
Review System: Users can leave reviews for recipes.
RESTful API: Follows RESTful principles for resource naming and HTTP methods.
Secure Password Storage: User passwords are securely hashed using bcrypt before storage.
git clone https://github.com/miky-rola/recipe-api.git
pip install -r requirements.txt
Create a .env file in the project root directory.
from dotenv import load_dotenv and import os to be able to load it from the .env
HOSTNAME=os.getenv("your_database_hostname")
DATABASE=os.getenv("your_database_name")
USER=os.getenv("your_database_username")
PASSWORD=os.getenv("your_database_password")
PORT_ID=os.getenv("your_database_port")
SECURITY=os.getenv("your_flask_secret_key")
flask run
Tested the endpoints using the RESTFUL API Extension
-
Register a new user account using the /users endpoint.
POST http://127.0.0.1:5000/users HTTP/1.1 content-type: application/json{ "username": "eva", "password": "123" }Respone
{ "message": "User created successfully", "user_id": 3 } -
log in using /login endpoint.
POST http://127.0.0.1:5000/login HTTP/1.1 content-type: application/json{ "username": "eva", "password": "123" }Response
{ "message": "Login successful" } -
Log out using /logout
DELETE http://127.0.0.1:5000/logout HTTP/1.1 content-type: application/jsonResponse
{ "message": "Logged out successfully" } -
Log in to obtain an authentication token.
-
Use the provided token for authentication in subsequent requests.
-
Create, retrieve, update, or delete recipes using the appropriate endpoints.
creating recipe
POST http://127.0.0.1:5000/recipes/create HTTP/1.1 content-type: application/json{ "recipe_name": "Waakye", "ingredients": "Rice and beans", "instructions": "Put on fire" }Response
{ "message": "Recipe created successfully", "recipe_id": 3 }Retrieve Recipes
GET http://127.0.0.1:5000/recipes HTTP/1.1 content-type: application/jsonResponse
{ "created_at": "2024-05-03 07:11:34", "ingredients": "Rice and beans", "instructions": "Put on fire", "recipe_id": 3, "recipe_name": "Waakye", "reviews": [ "I love it" ], "tags": [ "best recipe tag" ], "user": "eva" } -
Tag recipes with categories using the /tags endpoint.
Create, retrieve, update, or delete tags using the appropriate endpoints.
create tags
POST http://127.0.0.1:5000/recipes/3/tags HTTP/1.1 content-type: application/json
{ "tag_name": "best recipe tag" }
Response
{ "message": "Tag created successfully" }
-
Leave reviews for recipes using the /reviews endpoint.
Create, retrieve, update, or delete reviews using the appropriate endpoints.
creating a review
POST http://127.0.0.1:5000/recipes/3/reviews HTTP/1.1 content-type: application/json{ "review_content": "I love it" }Response
{ "message": "Review added successfully" } -
Uploading Files: Use the file upload functionality provided by
app.py.
-
Python
-
Flask
-
SQLAlchemy
Contributions are welcome! If you would like to contribute to the development of the Recipe API, please follow these steps:
-
Fork the repository.
-
Create a new branch for your feature or bug fix.
-
Make your changes and commit them with descriptive messages.
-
Push your changes to your fork.
-
Submit a pull request to the main repository's develop branch.