Skip to content

sule12/healthy_eating_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🥗 Healthy Eating API

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.


🚀 Tech Stack

  • Python 3.11+
  • Django 5.x
  • Django REST Framework
  • djangorestframework-simplejwt (JWT auth)
  • drf-yasg (Swagger & Redoc docs)
  • PostgreSQL Database

📦 Getting Started

1. Clone & setup

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.txt

2.Environment Variables

Create a .env (or export in your shell) and configure: DJANGO_SECRET_KEY=change-me DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1

Database (optional; defaults to SQLite if omitted)

DATABASE_URL=postgres://user:pass@localhost:5432/healthy_eating

Email (optional; for OTP/notifications if you enable email flows)

EMAIL_HOST=smtp.mailtrap.io EMAIL_PORT=587 EMAIL_HOST_USER=your_user EMAIL_HOST_PASSWORD=your_pass EMAIL_USE_TLS=True

Media

MEDIA_URL=/media/ MEDIA_ROOT=media

3. Running the project

python manage.py runserver

4. API Documentation

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/

5. Authentication

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/

6. API Endpoints

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/

6. Example Usage

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 test

Result 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'...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages