Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DAM Final API

A REST API built with FastAPI and SQL Server, serving as the backend for a recipe-listing app. It handles user authentication, recipe creation and browsing, ingredients, categories, and step-by-step instructions.

Built as the final project for a Mobile Application Development (DAM) course.

Features

  • JWT authentication — registration, login, and protected endpoints via OAuth2 password flow, with bcrypt password hashing
  • Recipes — create, fetch, and browse by author, category, or ingredient
  • Full-text style search — case-insensitive search across recipe titles, descriptions, ingredients, and categories
  • Ingredients & categories — CRUD-lite endpoints plus "top used" rankings (most popular ingredients/categories by recipe count)
  • Step-by-step instructions attached to each recipe
  • User management — profile lookup, password change, account deletion

Tech stack

Layer Technology
Framework FastAPI
ORM SQLAlchemy 2.0
Database Microsoft SQL Server (via pymssql)
Auth JWT (python-jose) + passlib/bcrypt
Validation Pydantic 2
Server Uvicorn
Hosting Replit

Project structure

app/
├── models/       # SQLAlchemy ORM models (User, Recipe, Ingredient, Category, Instruction, ...)
├── schemas/      # Pydantic request/response schemas
├── routers/      # API endpoints (auth, users, recipes, ingredients, categories, instructions)
├── security/     # JWT handling, password hashing, auth dependencies
├── config.py     # Environment-based settings
└── database.py   # SQLAlchemy engine/session setup
SQL/
├── TableCreation.sql  # Database schema (SQL Server)
└── MockData.sql       # Seed data for local testing
main.py           # Uvicorn entrypoint

Database schema

Seven related tables: users, recipes, categories, ingredients, instructions, recipe_categories (many-to-many) and recipe_ingredients (many-to-many with amount/unit). See SQL/TableCreation.sql for the full DDL.

Getting started

Prerequisites

  • Python 3.12
  • A SQL Server instance (local or remote) — connects via pymssql, no ODBC driver needed

Setup

git clone https://github.com/viribusegovis/DAM-Final-API.git
cd DAM-Final-API

python -m venv .venv
.venv\Scripts\activate      # Windows
source .venv/bin/activate   # macOS/Linux

pip install -r requirements.txt

Configuration

Create a .env file in the project root:

DB_SERVER=your-sql-server-host
DB_NAME=your-database-name
DB_USERNAME=your-db-username
DB_PASSWORD=your-db-password

JWT_SECRET=a-long-random-secret
JWT_ALGORITHM=HS256

Run the schema script against your database first:

sqlcmd -S <server> -d <database> -i SQL/TableCreation.sql

(Optionally load SQL/MockData.sql for sample recipes.)

Run

python main.py

The API starts on http://0.0.0.0:8080. Interactive docs are available at http://localhost:8080/docs (Swagger UI) and /redoc.

API overview

Method Endpoint Auth Description
POST /token Login, returns a JWT
POST /users/register Register a new user
GET /users/me Current user profile
GET /users/{user_id} Get user by ID
POST /users/password Change password
DELETE /users/deletion Delete own account
GET /recipes/ List all recipes
GET /recipes/{recipe_id} Recipe detail
GET /recipes/search?query= Search recipes
GET /recipes/category/{category_id} Recipes by category
GET /recipes/ingredient/{ingredient_id} Recipes by ingredient
GET /recipes/author/?author_id= Recipes by author
GET /recipes/{recipe_id}/ingredients Ingredients for a recipe
GET /recipes/{recipe_id}/instructions Instructions for a recipe
POST /recipes/ Create a recipe
GET /ingredients/ List ingredients
GET /ingredients/top/{limit} Most-used ingredients
GET /ingredients/search?query= Search ingredients
POST /ingredients/ Create an ingredient
GET /categories/ List categories
GET /categories/top Most-used categories
POST /categories/ Create a category
GET /instructions/ List instructions

Full interactive reference: /docs once the server is running.

License

Apache License 2.0

About

FastAPI + SQL Server REST API for a recipe-listing app - JWT auth, recipes, ingredients, categories and step-by-step instructions.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages