A Django + Django REST Framework backend for managing recipes, meal plans, and shopping lists, with JWT authentication and interactive API docs via Swagger and Redoc.
- Python 3.11+
- Django 5.x
- Django REST Framework
- djangorestframework-simplejwt (JWT auth)
- drf-yasg (Swagger & Redoc docs)
- PostgreSQL Database
git clone git@github.com:sule12/healthy_eating_api.git
cd healthy_eating
python3 -m venv ./venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtCreate a .env (or export in your shell) and configure: DJANGO_SECRET_KEY=change-me DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=postgres://user:pass@localhost:5432/healthy_eating
EMAIL_HOST=smtp.mailtrap.io EMAIL_PORT=587 EMAIL_HOST_USER=your_user EMAIL_HOST_PASSWORD=your_pass EMAIL_USE_TLS=True
MEDIA_URL=/media/ MEDIA_ROOT=media
python manage.py runserver
Swagger UI: http://127.0.0.1:8000/swagger/
Swagger JSON/YAML: http://127.0.0.1:8000/swagger.json / http://127.0.0.1:8000/swagger.yaml
Redoc: http://127.0.0.1:8000/redoc/
JWT-based authentication (SimpleJWT).
POST /api/auth/register/ – create a user (your authapp view)
POST /api/auth/token/ – obtain access & refresh tokens
POST /api/auth/token/refresh/ – refresh access token
POST /api/auth/logout/ – blacklist refresh token (your authapp view)
Example protected endpoint (requires Authorization: Bearer ):
e.g., GET /api/auth/protected/
Recipes
GET /api/recipes/ – List recipes
POST /api/recipes/ – Create recipe
GET /api/recipes/id/ – Retrieve recipe
PUT /api/recipes/id/ – Full update
PATCH /api/recipes/id/ – Partial update
DELETE /api/recipes/id/ – Delete
Meal Plans
GET /api/mealplans/, POST /api/mealplans/
GET/POST /api/meal/ – meal plan list/create
Shopping Lists
GET /api/shopping-lists/
GET /api/shopping-lists/shopping_list_id/items/
Register
curl -X POST http://127.0.0.1:8000/api/auth/register/ \
-H "Content-Type: application/json" \
-d '{"username":"suleiman","password":"StrongPass123$%","email":"sule@gmail.com"}'Login
curl -X POST http://127.0.0.1:8000/api/auth/token/ \
-H "Content-Type: application/json" \
-d '{"username":"alice","password":"StrongPass123"}'Response
{
"access": "<jwt-access>",
"refresh": "<jwt-refresh>"
}Accessing a protected Endpoint
curl http://127.0.0.1:8000/api/recipes/ \
-H "Authorization: Bearer <jwt-access>"Testing
python manage.py testResult of tests
(venv) ➜ backend git:(main) ✗ python manage.py test
Found 10 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..........
----------------------------------------------------------------------
Ran 10 tests in 0.929s
OK
Destroying test database for alias 'default'...