mirror of
https://github.com/wowlikon/LibraryAPI.git
synced 2025-12-11 21:30:46 +00:00
4a433f319112aea51e91b4c24cdf214ec0eb3d81
Book API
This project is a test web application built using FastAPI, a modern web framework for creating APIs in Python. It showcases the use of Pydantic for data validation, SQLModel for database interactions, Alembic for migration management, PostgreSQL as the database system, and Docker Compose for easy deployment.
Key Components:
- FastAPI: Provides high performance and simplicity for developing RESTful APIs, supporting asynchronous operations and automatic documentation generation.
- Pydantic: Used for data validation and serialization, allowing easy definition of data schemas.
- SQLModel: Combines SQLAlchemy and Pydantic, enabling database operations with Python classes.
- Alembic: A tool for managing database migrations, making it easy to track and apply changes to the database schema.
- PostgreSQL: A reliable relational database used for data storage.
- Docker Compose: Simplifies the deployment of the application and its dependencies in containers.
Installation Instructions
For development:
-
Clone the repository:
git clone https://github.com/wowlikon/bookapi.git -
Navigate to the project directory:
cd bookapi -
Copy and configure environment variables:
cp .env.example .env -
Build the Docker containers:
docker-compose build --no-cache -
Run the application:
docker-compose up
For make new migrations:
docker-compose run api alembic revision --autogenerate -m "Migration name"
For apply migrations:
-
Build the Docker containers:
docker-compose build --no-cache -
Run database container:
docker-compose up -d db -
Run this command:
docker-compose run --rm api alembic upgrade head
API Endpoints
Authors
| Method | Endpoint | Description |
|---|---|---|
| POST | /author |
Create a new author |
| GET | /author |
Retrieve a list of all authors |
| PUT | /author/{id} |
Update a specific author by ID |
| DELETE | /author/{id} |
Delete a specific author by ID |
Books
| Method | Endpoint | Description |
|---|---|---|
| POST | /books |
Create a new book |
| GET | /books |
Retrieve a list of all books |
| PUT | /books/{id} |
Update a specific book by ID |
| DELETE | /books/{id} |
Delete a specific book by ID |
Technologies Used
- FastAPI: A modern web framework for building APIs with Python, known for its speed and ease of use.
- Pydantic: A data validation and settings management library that uses Python type annotations.
- SQLModel: A library for interacting with databases using Python classes, combining the features of SQLAlchemy and Pydantic.
- Alembic: A lightweight database migration tool for use with SQLAlchemy.
- PostgreSQL: A powerful, open-source relational database management system.
- Docker: A platform for developing, shipping, and running applications in containers.
- Docker Compose: A tool for defining and running multi-container Docker applications.
TODO List
- Split models for API and database
- Implement tests
Languages
Python
95.2%
HTML
2.8%
Mako
1%
Dockerfile
1%