This is a simple REST API built with FastAPI for managing books.
It provides endpoints for creating, reading, and deleting books.
It uses Pydantic for data validation and serialization.
This project is organized as a Python package called books
with the following files:
utils.py
: Contains utility functions.schemas.py
: Defines Pydantic models for data validation and serialization.openapi.py
: Contains OpenAPI response types and error models.api.py
: Defines FastAPI routes.main.py
: Entry point of the application, creating a FastAPI application and including the router fromapi.py
.
To use this project, you need Python 3.11 or higher.
-
Clone this repository.
-
Navigate to the repo directory.
-
Install poetry
-
Install project:
poetry shell poetry install
-
Run the application:
uvicorn main:app --app-dir books --reload
-
Open your browser and visit
http://127.0.0.1:8000/docs
.
POST /books
: Create a new book.GET /books
: List all books.GET /books/{book_id}
: Retrieve a specific book by ID.DELETE /books/{book_id}
: Delete book.
This project also includes a suite of tests to verify the functionality of the API. To run the tests, use the following command:
poe test