Notes API (Python)
A RESTful notes management API built with FastAPI. The project demonstrates idiomatic Python API design: Pydantic schemas for validation, SQLAlchemy for ORM-based data access, and a clean separation between route handlers and CRUD logic.
Tech
API
Five endpoints cover the full CRUD surface for notes:
- POST /notes — create a new note; returns the created resource.
- GET /notes — retrieve all notes as a list.
- GET /notes/{note_id} — fetch a single note by ID; returns 404 if not found.
- PUT /notes/{note_id} — update title and content; returns 404 if not found.
- DELETE /notes/{note_id} — remove a note and return the deleted resource.
Architecture
- CRUD layer — database operations are isolated in
crud.py, keeping route handlers inmain.pythin and focused on HTTP concerns. - Pydantic schemas —
NoteCreate,NoteUpdate, andNoteResponseenforce input validation and shape the API contract independently of the ORM model. - SQLAlchemy ORM — the
Notemodel maps to a SQLite table; sessions are managed via FastAPI dependency injection with atry/finallyteardown to guarantee cleanup. - Auto-generated docs — FastAPI serves interactive Swagger UI and ReDoc out of the box at
/docsand/redoc.