REST API Workshop, created for the 4.0 Solutions workshop series on MCP and Agentic AI
This is a RESTful API for managing a public library system using FastAPI. It includes resources for branches, patrons, loans, books, authors, and library-system (singleton).
- CRUD operations for each resource.
- Uses SQLAlchemy with SQLite for persistence.
- Pydantic for schema validation.
- Follows REST principles with proper HTTP status codes.
- Library-system is a singleton resource (only one instance allowed).
app/main.py: FastAPI app entry point.app/database.py: Database configuration.app/models/: SQLAlchemy ORM models.app/schemas/: Pydantic schemas.app/crud/: CRUD functions.app/routers/: API routers.
- Create virtual env:
python -m venv venv - Activate:
venv\Scripts\activate(Windows) orsource venv/bin/activate(macOS/Linux) - Install deps:
pip install -r requirements.txt - Run:
uvicorn app.main:app --reload
Access docs at http://127.0.0.1:8000/docs.
Open a terminal in the library-api-basic/ directory.
Run: > python -m venv venv
This creates a virtual environment named venv.
On Windows:
> .\venv\Scripts\activate.ps1On macOS/Linux:
source venv/bin/activateWith the virtual environment activated, run:
pip install -r requirements.txtThis installs all required packages from the requirements.txt file.
With the virtual environment activated, run: uvicorn app.main:app --reload
This starts the FastAPI server on http://127.0.0.1:8000.
Visit http://127.0.0.1:8000/docs in your browser for the interactive Swagger UI to test the API.
- Database: SQLite (
library.db). - Relationships: Books link to authors; loans link to books, patrons, branches.