https://github.com/wearymench/book_manager
A Flask-based RESTful API for managing books
https://github.com/wearymench/book_manager
flask python
Last synced: about 2 months ago
JSON representation
A Flask-based RESTful API for managing books
- Host: GitHub
- URL: https://github.com/wearymench/book_manager
- Owner: WearyMench
- Created: 2025-05-05T18:17:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-06T00:16:59.000Z (about 1 year ago)
- Last Synced: 2025-05-07T00:51:38.449Z (about 1 year ago)
- Topics: flask, python
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Book Manager API
A Flask-based RESTful API for managing books with features like input validation, rate limiting, logging, and API documentation.
## Features
- RESTful API endpoints for CRUD operations on books
- Input validation using Marshmallow
- Rate limiting to prevent abuse
- Swagger/OpenAPI documentation
- Error handling
- CORS support
- Unit tests
## Installation
### Option 1: Local Installation
1. Clone the repository
2. Create a virtual environment:
```bash
python -m venv env
source env/bin/activate # On Windows: .\env\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Create a .env file with your configuration:
- `FLASK_ENV`: Application environment (development)
- `SECRET_KEY`: Flask secret key
- `POSTGRES_USER`: PostgreSQL username
- `POSTGRES_PASSWORD`: PostgreSQL password
- `POSTGRES_DB`: PostgreSQL database name
- `SQLALCHEMY_DATABASE_URI`: Database connection string
### Option 2: Docker Installation
1. Make sure you have Docker and Docker Compose installed
2. Clone the repository
3. Build and run the containers:
```bash
docker-compose up --build
```
The API will be available at `http://localhost:5000`
## Database Migrations
Initialize the database:
```bash
flask db upgrade
```
Create a new migration after model changes:
```bash
flask db migrate -m "Migration description"
flask db upgrade
```
## Running the Application
### Local Development
Development mode:
```bash
flask run
```
Production mode:
```bash
gunicorn -w 4 -b 0.0.0.0:5000 app:app
```
### Using Docker
Start the application:
```bash
docker-compose up
```
Run in detached mode:
```bash
docker-compose up -d
```
Stop the application:
```bash
docker-compose down
```
## API Documentation
Once running, visit `http://localhost:5000/` to access the Swagger UI documentation.
## Testing
Run tests using pytest:
```bash
pytest
```
## API Endpoints
- GET /books - List all books
- POST /books - Create a new book
- PUT /books/{id} - Update a book
- DELETE /books/{id} - Delete a book
## Rate Limits
- List books: 100 requests per hour
- Create/Update/Delete: 20 requests per hour
- Overall: 200 requests per day
## Directory Structure
```
.
├── app.py # Main application file
├── config.py # Configuration settings
├── models.py # Database models
├── schemas.py # Validation schemas
├── errors.py # Error handling
├── logging.py # Logging configuration
├── tests/ # Test files
├── logs/ # Log files
└── requirements.txt # Project dependencies
```