Skip to content

mgadhvi/fastapi-library-example

Repository files navigation

Simple FastAPI Library API

Overview

This is a minimalist FastAPI backend designed to manage library records. It provides a RESTful interface and persists data using a PostgreSQL database.

Prerequisites

  • Python 3.8+
  • PostgreSQL
  • pip (latest version)

Configuration

The application uses environment variables for configuration. Create a file named .env in the root directory:

DATABASE_URL=postgresql://user:password@localhost:5432/library_db

Installation

Follow these steps to prepare your local environment:

1. Dependencies

Update pip and install the required packages:

python3 -m pip install --upgrade pip
pip install -r requirements.txt

2. Database Seeding

Initialize the PostgreSQL schema and populate the database with initial data:

python3 seed.py

API Endpoints

Authors

MethodEndpointDescription
POSTauthorsCreate Author
GETauthorsRead Authors
GET/authors/{author_id}Read Author

Books

MethodEndpointDescription
POSTbooksCreate Book
GETbooksRead Books
GET/books/{book_id}Read Book
PATCH/books/{book_id}Update Book
DELETE/books/{book_id}Delete Book

Execution

Launch the development server using the FastAPI CLI:

fastapi dev

The API will be available at http://localhost:8000. You can access the auto-generated documentation (Swagger UI) at http://localhost:8000/docs.

About

Simple program to demonstrate the use of FastAPI, SQLAlchemy and Pydantic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors