FastAPI REST API Service

This is a FastAPI-based REST API with user authentication, built with SQLite for data storage.

Features

  • User registration and authentication with JWT tokens
  • FastAPI automatic Swagger documentation
  • SQLAlchemy ORM for database operations
  • Alembic migrations for database versioning
  • Password hashing with bcrypt
  • Health check endpoint

Getting Started

Prerequisites

  • Python 3.8+
  • SQLite

Installation

  1. Clone the repository:
git clone <repository-url>
cd genericrestapiservice
  1. Install the dependencies:
pip install -r requirements.txt
  1. Apply the database migrations:
alembic upgrade head
  1. Run the application:
uvicorn main:app --reload

The API will be available at http://localhost:8000.

API Documentation

Once the application is running, you can access the following documentation:

API Endpoints

Health Check

  • GET /health - Check if the API is healthy

Users

  • POST /users - Register a new user
  • POST /users/token - Get an access token (login)
  • GET /users/me - Get the current authenticated user
  • GET /users/{user_id} - Get a user by ID

Database

The application uses SQLite as the database. The database file is stored at /app/storage/db/db.sqlite.

Migrations

Database migrations are managed with Alembic. To apply migrations:

alembic upgrade head

To create a new migration:

alembic revision -m "description"

Development

Code Structure

  • app/ - Main application directory
    • models/ - SQLAlchemy models
    • schemas/ - Pydantic schemas
    • routers/ - FastAPI routers
    • utils.py - Utility functions
    • database.py - Database configuration
  • alembic/ - Alembic migrations
  • main.py - Application entry point

Running Tests

pytest
Description
Project: Generic REST API Service
Readme 42 KiB
Languages
Python 94.1%
Mako 3.7%
Shell 2.2%