https://github.com/linthithtwe/dashboard-fastapi-backend
A simple FastAPI REST API data querying, pagination, and performance optimization with Redis caching.
https://github.com/linthithtwe/dashboard-fastapi-backend
fastapi python redis rest-api
Last synced: about 2 months ago
JSON representation
A simple FastAPI REST API data querying, pagination, and performance optimization with Redis caching.
- Host: GitHub
- URL: https://github.com/linthithtwe/dashboard-fastapi-backend
- Owner: LinThitHtwe
- Created: 2025-07-25T08:26:09.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-28T17:59:42.000Z (11 months ago)
- Last Synced: 2025-07-28T18:40:41.699Z (11 months ago)
- Topics: fastapi, python, redis, rest-api
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sample Product Rest API using FastAPI
This project is a simple Product REST API built with Python FastAPI. It uses PostgreSQL as the database and Redis for caching to improve performance. The main focus is on building clean and efficient REST API endpoints that support data retrieval with filtering, sorting, pagination, and exception handling.
## Features
- FastAPI backend with async SQLAlchemy
- PostgreSQL database
- Redis caching (via fastapi-cache2)
- Filtering, sorting, and pagination for product listing
- Pydantic models and validation
- Centralized exception handling and logging
- Docker & docker-compose support
## Main Focus of development
- **Global Exception Handling:** All errors are caught and returned in a consistent, structured format, to make debugging and client integration easier.
- **Redis Caching:** Queries are cached, reducing latency and database load.
## Project Structure
```
.
├── docker-compose.yml
├── dockerfile
├── requirement.txt
├── .env.sample
├── src/
│ ├── main.py
│ ├── core/
│ ├── db/
│ ├── models/
│ ├── routes/
│ ├── schemas/
│ ├── services/
│ ├── common/
│ └── constants/
```
## API Highlights
- `GET /products/` — List products with advanced filtering, sorting, and pagination
- `GET /products/{product_id}` — Retrieve a single product by ID
- `POST /products/` — Create a new product
- `PUT /products/{product_id}` — Update a product
## Dependencies
```txt
python==3.13.4
fastapi==0.116.1
uvicorn==0.35.0
sqlalchemy==2.0.41
asyncpg==0.30.0
pydantic==2.11.7
pydantic-settings==2.10.1
python-dotenv==1.1.1
fastapi-cache2==0.2.2
redis==6.2.0
aioredis==2.0.1
Faker==37.4.2
```
## Frontend Project Url
[https://github.com/LinThitHtwe/dashboard-nextjs-frontend](https://github.com/LinThitHtwe/dashboard-nextjs-frontend)
## Configuration & Setup
Below are the steps to run this project locally
### 1. Clone the Repository
```bash
git clone https://github.com/LinThitHtwe/dashboard-fastapi-backend
cd dashboard-fastapi-backend
```
---
### 2. Install Dependencies
```bash
pip install -r requirements.txt
```
---
### 3. Setup Environment Variables
Create a `.env` file in the root directory and add the following variables:
```env
DATABASE_URL=postgresql+asyncpg://:@localhost:5432/
REDIS_URL=redis://localhost:6379
```
---
### 4. Seed Sample Data (Optional)
```bash
python -m db.seed
```
---
### 5. Start the FastAPI Server
```bash
uvicorn src.main:app --reload
```
Visit: [http://localhost:8000/docs](http://localhost:8000/docs) for the interactive Swagger UI.
---