Skip to content

Repository files navigation

Books API

A lightweight Flask REST API for managing books without a database. Book data is stored in a local JSON file so the project remains simple and easy to run locally.

Features

  • CRUD operations for books
  • JSON file-based persistence
  • Swagger/OpenAPI documentation
  • environment-driven configuration
  • easy Postman testing

Tech Stack

  • Python 3
  • Flask 3.x
  • Flasgger
  • Gunicorn for production serving

Project Structure

  • app.py - Flask app and API endpoints
  • requirements.txt - project dependencies
  • data/books.json - local storage for books
  • Books_LocalHost.postman_collection.json - Postman requests
  • tests/test_app.py - API regression tests

Setup

  1. Clone or download this repository.
  2. Open a terminal in the project folder.
  3. Create and activate a virtual environment (optional but recommended):
python -m venv .venv
.venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Run the API

python app.py

The app runs by default on:

Swagger Docs

Swagger UI is available at:

Environment Variables

You can override the default file storage and runtime settings with environment variables:

set BOOKS_DATA_FILE=C:\path\to\books.json
set HOST=0.0.0.0
set PORT=5000

If not provided, the app uses:

  • data/books.json
  • 0.0.0.0
  • 5000

API Endpoints

GET /books

Returns all books.

POST /books

Creates a new book.

Example body:

{
  "name": "Clean Code",
  "price": 399,
  "isbn": 102,
  "author": "Robert C. Martin"
}

GET /books/

Returns a single book matched by ISBN.

PUT /books/

Replaces an existing book by ISBN.

PATCH /books/

Updates selected fields on an existing book without replacing the full record.

Example body:

{
  "price": 450,
  "author": "Updated Author"
}

DELETE /books/

Deletes a book by ISBN.

Postman

  1. Open Postman.
  2. Import Books_LocalHost.postman_collection.json.
  3. Ensure the collection uses the local server URL http://127.0.0.1:5000.
  4. Run the requests in order or individually.

Optional: run collection with Newman

npm install -g newman
newman run Books_LocalHost.postman_collection.json

Notes

  • No database is used in this project.
  • Data persists in the JSON file configured by BOOKS_DATA_FILE.
  • For production, it is recommended to move this to a proper database and add authentication/validation as needed.

About

Simple Books API with Flask

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages