Automated Action 7fdb11e728 Create FastAPI REST API with SQLite database and CRUD operations
- Set up project structure with FastAPI, SQLAlchemy, and Alembic
- Create database models for User and Item
- Implement CRUD operations for all models
- Create API endpoints with validation
- Add health check endpoint
- Configure CORS middleware
- Set up database migrations
- Add comprehensive documentation in README
2025-05-21 08:51:23 +00:00
2025-05-21 08:44:08 +00:00

Generic REST API Service

A RESTful API built with FastAPI and SQLite, providing endpoints for user and item management.

Features

  • User management (create, read, update, delete)
  • Item management (create, read, update, delete)
  • SQLite database with SQLAlchemy ORM
  • Alembic migrations
  • OpenAPI documentation (Swagger UI)
  • Password hashing with bcrypt
  • Health check endpoint

Requirements

  • Python 3.8+
  • FastAPI
  • SQLAlchemy
  • Alembic
  • Uvicorn
  • Pydantic
  • Other dependencies as listed in requirements.txt

Project Structure

.
├── app/
│   ├── api/
│   │   ├── endpoints/
│   │   │   ├── items.py
│   │   │   └── users.py
│   │   ├── api.py
│   │   └── deps.py
│   ├── core/
│   │   ├── config.py
│   │   └── security.py
│   ├── crud/
│   │   ├── base.py
│   │   ├── crud_item.py
│   │   └── crud_user.py
│   ├── database/
│   │   ├── base.py
│   │   ├── base_class.py
│   │   └── session.py
│   ├── models/
│   │   ├── item.py
│   │   └── user.py
│   └── schemas/
│       ├── item.py
│       └── user.py
├── migrations/
│   └── versions/
│       └── 20240520_initial.py
├── storage/
│   └── db/
│       └── db.sqlite
├── alembic.ini
├── main.py
└── requirements.txt

Installation

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

Running the Application

Start the application using Uvicorn:

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

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

API Documentation

API Endpoints

Health Check

  • GET /health - Check the API health status

Users

  • GET /api/v1/users/ - List all users
  • POST /api/v1/users/ - Create a new user
  • GET /api/v1/users/{user_id} - Get user details
  • PUT /api/v1/users/{user_id} - Update user information
  • DELETE /api/v1/users/{user_id} - Delete a user

Items

  • GET /api/v1/items/ - List all items
  • POST /api/v1/items/ - Create a new item
  • GET /api/v1/items/{id} - Get item details
  • PUT /api/v1/items/{id} - Update item information
  • DELETE /api/v1/items/{id} - Delete an item
  • GET /api/v1/items/user/{owner_id} - List all items owned by a specific user

Development

Database Migrations

Generate a new migration:

alembic revision -m "description"

Apply migrations:

alembic upgrade head

Revert migrations:

alembic downgrade -1
Description
Project: Generic REST API Service
Readme 43 KiB
Languages
Python 97.6%
Mako 2.4%