Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + Pydantic + Redis – E2E Backend Project

A fully working end-to-end backend built with FastAPI, Pydantic v2, and Redis.

Features

  • RESTful Item CRUD API (Create / Read / Update / Delete)
  • Request/response validation with Pydantic v2 models
  • Data persistence in Redis (no ORM required)
  • Auto-generated interactive docs at /docs (Swagger UI) and /redoc
  • Environment-variable based configuration

Project structure

fastapi/
├── app/
│   ├── config.py          # Redis connection settings from env vars
│   ├── main.py            # FastAPI application factory
│   ├── models/
│   │   └── item.py        # Pydantic models (ItemCreate, ItemUpdate, Item)
│   ├── routes/
│   │   └── items.py       # Item API router
│   └── services/
│       ├── item_service.py # Business logic + Redis CRUD helpers
│       └── redis_client.py # Lazily-initialised Redis connection
├── main.py                # Entry-point for uvicorn
└── requirements.txt

Quick start

1. Install dependencies

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt

2. Start Redis

# Docker (recommended)
docker run -d -p 6379:6379 redis:7-alpine

# or use a local installation
redis-server

3. Run the API server

uvicorn app.main:app --reload

The server starts at http://localhost:8000.
Interactive docs: http://localhost:8000/docs

Configuration (environment variables)

Variable Default Description
REDIS_HOST localhost Redis server hostname
REDIS_PORT 6379 Redis server port
REDIS_DB 0 Redis logical database
REDIS_PASSWORD (none) Redis AUTH password

API endpoints

Method Path Description
GET / Health check
POST /items/ Create a new item
GET /items/ List all items
GET /items/{id} Get a single item
PUT /items/{id} Update an item
DELETE /items/{id} Delete an item

Example – create an item

curl -X POST http://localhost:8000/items/ \
  -H "Content-Type: application/json" \
  -d '{"name": "Widget", "description": "A handy widget", "price": 9.99, "in_stock": true}'

About

Creating a e2e project using fastapi

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages