Skip to content

Full-stack FastAPI application demonstrating CRUD operations with PostgreSQL, SQLAlchemy ORM, Pydantic schemas, and environment-based configuration

Notifications You must be signed in to change notification settings

zain-cs/fastapi-postgresql-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + PostgreSQL CRUD API

A RESTful API built with FastAPI and PostgreSQL for managing posts.

Features

  • ✅ Create, Read, Update, Delete (CRUD) operations
  • ✅ PostgreSQL database with SQLAlchemy ORM
  • ✅ Pydantic schemas for data validation
  • ✅ Auto-generated API documentation

Setup

  1. Clone the repository
   git clone <your-repo-url>
   cd <repo-name>
  1. Create virtual environment
   python -m venv venv
  1. Activate virtual environment
   # Windows PowerShell
   .\venv\Scripts\Activate.ps1
   
   # Windows CMD
   .\venv\Scripts\activate.bat
   
   # Mac/Linux
   source venv/bin/activate
  1. Install dependencies
   pip install -r requirements.txt
  1. Create .env file
   # Create .env file in the root directory
   DATABASE_URL=postgresql://username:password@localhost:5432/database_name
   SECRET_KEY=your-secret-key-here
  1. Run the application
   uvicorn main:app --reload

API Endpoints

Method Endpoint Description
GET / Welcome message
GET /posts Get all posts
POST /posts Create a new post
GET /posts/{id} Get post by ID
PUT /posts/{id} Update post by ID
DELETE /posts/{id} Delete post by ID

API Documentation

After running the app, visit:

Technologies Used

  • FastAPI
  • PostgreSQL
  • SQLAlchemy
  • Pydantic
  • Uvicorn

About

Full-stack FastAPI application demonstrating CRUD operations with PostgreSQL, SQLAlchemy ORM, Pydantic schemas, and environment-based configuration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages