Skip to content

About

REST API template with FastAPI, JWT authentication, SQLAlchemy and CRUD endpoints. Linted and tested with GitHub Actions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🚀 FastAPI REST Boilerplate

A professional REST API template with JWT, full CRUD, and Swagger

CI Python FastAPI SQLAlchemy License GitHub


📌 About the Project

A professional, production-ready REST API template built with FastAPI. Includes JWT authentication, full CRUD operations, a SQLAlchemy-backed database, Pydantic validation, and automatic Swagger documentation — all structured in a modular, scalable way.

Features

  • ✅ JWT authentication — registration, login, and route protection
  • ✅ Full CRUD for users and items
  • ✅ SQLAlchemy ORM with SQLite (swappable for PostgreSQL/MySQL)
  • ✅ Automatic validation with Pydantic v2
  • ✅ Secure password hashing with bcrypt
  • ✅ Automatic Swagger UI at /docs
  • ✅ Modular, scalable structure with routers
  • ✅ CORS configured for frontend integration

🛠️ Technologies

  • FastAPI — Modern, high-performance web framework
  • SQLAlchemy — Database ORM
  • Pydantic — Data validation and serialization
  • python-jose — JWT token generation and validation
  • passlib + bcrypt — Secure password hashing
  • Uvicorn — ASGI server

📁 Structure

fastapi-rest-boilerplate/
├── app/
│   ├── main.py              # Entry point
│   ├── database.py          # Database configuration
│   ├── models.py            # SQLAlchemy models
│   ├── schemas.py           # Pydantic schemas
│   ├── auth.py              # JWT logic
│   └── routers/
│       ├── auth.py          # Registration and login
│       ├── users.py         # User endpoints
│       └── items.py         # Item endpoints (CRUD)
├── tests/
├── .github/workflows/ci.yml
├── requirements.txt
├── requirements-dev.txt
├── .env.example
└── README.md

📦 Installation

git clone https://github.com/LacerdaTraderCode/fastapi-rest-boilerplate.git
cd fastapi-rest-boilerplate

python -m venv venv
source venv/bin/activate      # Linux/Mac
# venv\Scripts\activate       # Windows

pip install -r requirements.txt

cp .env.example .env
# Edit .env and set SECRET_KEY

uvicorn app.main:app --reload

Visit http://localhost:8000/docs for the interactive documentation.


📡 Endpoints

Authentication

Method Endpoint Description
POST /auth/register Register a new user
POST /auth/login Login — returns a JWT token

Users (authenticated)

Method Endpoint Description
GET /users/me Authenticated user's data

Items (authenticated)

Method Endpoint Description
GET /items/ List all items
POST /items/ Create a new item
GET /items/{id} Get item by ID
PUT /items/{id} Update item
DELETE /items/{id} Delete item

⚡ Usage Example via cURL

# Register
curl -X POST "http://localhost:8000/auth/register" \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "password": "password123"}'

# Login
curl -X POST "http://localhost:8000/auth/login" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=user@example.com&password=password123"

# Use token
curl -X GET "http://localhost:8000/items/" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

🧪 Development

pip install -r requirements-dev.txt
ruff check . && ruff format --check .
pytest -v

Tests run against an isolated in-memory SQLite database. The same checks run on every push and pull request via GitHub Actions.


🚀 Deploy

Ready for deployment on:

  • Railway, Render, Fly.io — free tiers
  • AWS, Google Cloud, Azure
  • Docker — add a Dockerfile as needed

✅ Requirements

  • Python 3.11 or higher

👤 Author

Wagner Lacerda — Senior Software Engineer | Python, Backend, AI Apps, Automation & Systems

GitHub LinkedIn YouTube Telegram Telegram Bots

📍 Rio Grande do Sul, Brazil


📄 License

Distributed under the MIT license. See LICENSE for more details.

About

REST API template with FastAPI, JWT authentication, SQLAlchemy and CRUD endpoints. Linted and tested with GitHub Actions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages