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
- Clone the repository:
git clone <repository-url>
cd genericrestapiservice
- Install the dependencies:
pip install -r requirements.txt
- Apply the database migrations:
alembic upgrade head
- 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:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Health Check
GET /health
- Check if the API is healthy
Users
POST /users
- Register a new userPOST /users/token
- Get an access token (login)GET /users/me
- Get the current authenticated userGET /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 directorymodels/
- SQLAlchemy modelsschemas/
- Pydantic schemasrouters/
- FastAPI routersutils.py
- Utility functionsdatabase.py
- Database configuration
alembic/
- Alembic migrationsmain.py
- Application entry point
Running Tests
pytest
Description
Languages
Python
94.1%
Mako
3.7%
Shell
2.2%