My Recipes API is a FastAPI project designed to manage a collection of recipes, where users can add, update, and retrieve recipes, including details like ingredients, preparation steps, and categories.
-
User Management: Allows users to register, with the first user automatically assigned the role of admin.
-
Recipe Management:
-
Create, update, delete, and retrieve recipes.
-
Associate recipes with specific categories (e.g., vegetarian, desserts).
-
Categories can be created dynamically.
-
Security: Password hashing for user security.
-
Validation: Data validation using Pydantic models.
-
Python 3.9 or above
-
FastAPI
-
Uvicorn
-
SQLAlchemy
-
Pydantic
-
SQLite
-
Clone the repository:
git clone https://github.com/jp-cortes/my-recipes-api.git cd my-recipes-api
-
Create a virtual environment:
python -m venv env
source env/bin/activate # On Windows: `env\Scripts\activate`
- Install the dependencies:
pip install -r requirements.txt
- Set up your database:
Modify the DATABASE_URL in config.py to match your database connection string.
Run database migrations if applicable.
- Start the server:
uvicorn main:app --reload
The API will be available at http://127.0.0.1:8000.
-
POST
/register
: Create a new user. -
Admin role is assigned to the first user.
-
GET
/categories/
: Retrieve all categories. -
POST
/category/
: Create a new category. -
PUT
/category/{id}
: Update an existing category by ID. -
GET
/category/{id}
: Retrieve a single category by ID.
-
POST
/recipe/
: Create a new recipe. -
PUT
/recipe/{id}
: Update an existing recipe by ID. -
GET
/recipes/
: Retrieve all recipes. -
GET
/recipes/category/{id}
: Retrieve recipes by category ID. -
GET
/recipe/{id}
: Retrieve a single recipe by ID. -
DELETE
/recipe/{id}
: Delete a recipe by ID.
{
"title": "Greek Salad",
"images": ["salad_01.png", "salad_02.png", "salad_03.png"],
"ingredients": ["tomato", "cucumber", "feta", "olive oil"],
"preparation": "Mix all ingredients and add olive oil.",
"category_id": 1
}
{
"name": "John Doe",
"email": "[email protected]",
"password": "your-password",
"role": "user" # Auto-assigned as "admin" for the first user
}
{
"title": "Salad",
"images": ["salad_01.png", "salad_02.png", "salad_03.png"],
"ingredients": ["tomato", "lettuce", "olive oil"],
"preparation": "Chop ingredients, mix, and add olive oil",
"category": "Vegetarian",
"category_id": 1
}
my-recipes-api/
│ ├── main.py # FastAPI application setup
│ ├── models/ # SQLAlchemy models (User, Recipe, Category)
│ ├── schemas/ # Pydantic models (User, Recipe, Category)
│ ├── config/ # Database connection and setup will be genarated automatically after running the server for the first time
│ ├── middlewares/ # Custom middleware (error handling, etc.)
│ ├── services/ # APi services
├── tests/ # Unit tests
├── README.md # This file
└── requirements.txt # Python dependencies