Automated Action 12b80aca5b Implement and optimize Calculator API with FastAPI and SQLAlchemy
- Fixed Pydantic configuration using ConfigDict for latest Pydantic version
- Fixed import order in alembic/env.py for proper module imports
- Applied code formatting with Ruff
- Optimized database connection settings
- Ensured proper error handling for API endpoints

generated with BackendIM... (backend.im)
2025-05-13 23:22:34 +00:00

Calculator API

A simple calculator API built with FastAPI and SQLAlchemy that performs basic arithmetic operations and stores calculation history.

Features

  • Basic arithmetic operations (add, subtract, multiply, divide)
  • Square root calculation
  • Calculation history storage in SQLite database
  • Health check endpoint

API Endpoints

Calculator Operations

  • POST /api/v1/calculator/ - Perform a calculation
  • GET /api/v1/calculator/history - Get calculation history
  • GET /api/v1/calculator/{calculation_id} - Get a specific calculation

Health Check

  • GET /api/v1/health - API health status

Installation

# Clone the repository
git clone <repository-url>

# Install dependencies
pip install -r requirements.txt

# Run migrations
alembic upgrade head

# Start the API
uvicorn main:app --reload

Environment Variables

Create a .env file in the root directory with the following variables:

# No environment variables required for basic setup

API Documentation

Once the API is running, you can access the API documentation at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Example Usage

Perform Addition

POST /api/v1/calculator/
{
  "operation": "add",
  "first_number": 5,
  "second_number": 3
}

Response:

{
  "id": 1,
  "operation": "add",
  "first_number": 5,
  "second_number": 3,
  "result": 8,
  "created_at": "2025-05-13T12:00:00.000Z"
}

Perform Square Root

POST /api/v1/calculator/
{
  "operation": "square_root",
  "first_number": 16
}

Response:

{
  "id": 2,
  "operation": "square_root",
  "first_number": 16,
  "second_number": null,
  "result": 4,
  "created_at": "2025-05-13T12:01:00.000Z"
}
Description
Project: Calculator API
Readme 44 KiB
Languages
Python 95.6%
Mako 4.4%