https://github.com/hngprojects/fastapi-book-project
https://github.com/hngprojects/fastapi-book-project
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hngprojects/fastapi-book-project
- Owner: hngprojects
- License: mit
- Created: 2025-02-13T16:21:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-13T16:22:22.000Z (over 1 year ago)
- Last Synced: 2025-06-07T03:08:26.324Z (about 1 year ago)
- Language: Python
- Size: 5.86 KB
- Stars: 0
- Watchers: 7
- Forks: 145
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastAPI Book Management API
## Overview
This project is a RESTful API built with FastAPI for managing a book collection. It provides comprehensive CRUD (Create, Read, Update, Delete) operations for books with proper error handling, input validation, and documentation.
## Features
- ๐ Book management (CRUD operations)
- โ
Input validation using Pydantic models
- ๐ Enum-based genre classification
- ๐งช Complete test coverage
- ๐ API documentation (auto-generated by FastAPI)
- ๐ CORS middleware enabled
## Project Structure
```
fastapi-book-project/
โโโ api/
โ โโโ db/
โ โ โโโ __init__.py
โ โ โโโ schemas.py # Data models and in-memory database
โ โโโ routes/
โ โ โโโ __init__.py
โ โ โโโ books.py # Book route handlers
โ โโโ router.py # API router configuration
โโโ core/
โ โโโ __init__.py
โ โโโ config.py # Application settings
โโโ tests/
โ โโโ __init__.py
โ โโโ test_books.py # API endpoint tests
โโโ main.py # Application entry point
โโโ requirements.txt # Project dependencies
โโโ README.md
```
## Technologies Used
- Python 3.12
- FastAPI
- Pydantic
- pytest
- uvicorn
## Installation
1. Clone the repository:
```bash
git clone https://github.com/hng12-devbotops/fastapi-book-project.git
cd fastapi-book-project
```
2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
## Running the Application
1. Start the server:
```bash
uvicorn main:app
```
2. Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## API Endpoints
### Books
- `GET /api/v1/books/` - Get all books
- `GET /api/v1/books/{book_id}` - Get a specific book
- `POST /api/v1/books/` - Create a new book
- `PUT /api/v1/books/{book_id}` - Update a book
- `DELETE /api/v1/books/{book_id}` - Delete a book
### Health Check
- `GET /healthcheck` - Check API status
## Book Schema
```json
{
"id": 1,
"title": "Book Title",
"author": "Author Name",
"publication_year": 2024,
"genre": "Fantasy"
}
```
Available genres:
- Science Fiction
- Fantasy
- Horror
- Mystery
- Romance
- Thriller
## Running Tests
```bash
pytest
```
## Error Handling
The API includes proper error handling for:
- Non-existent books
- Invalid book IDs
- Invalid genre types
- Malformed requests
## Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit changes (`git commit -m 'Add AmazingFeature'`)
4. Push to branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Support
For support, please open an issue in the GitHub repository.