
🤖 Generated with BackendIM... (backend.im)
Co-Authored-By: Claude <noreply@anthropic.com>
Number Divisibility API
A simple REST API built with FastAPI that checks if a number is divisible by 2.
Features
- Check if a number is divisible by 2 via GET or POST requests
- History endpoint to view all past checks
- Database integration with SQLAlchemy and SQLite
- Database migrations managed by Alembic
- Health endpoint for monitoring
- OpenAPI documentation built-in
API Endpoints
GET /
Welcome message for the API.
GET /divisibility/{number}
Check if a number is divisible by 2 using a path parameter.
Parameters:
number
(integer): The number to check
Response:
{
"number": 42,
"is_divisible_by_2": true
}
POST /divisibility
Check if a number is divisible by 2 using a JSON request body.
Request Body:
{
"number": 42
}
Response:
{
"number": 42,
"is_divisible_by_2": true
}
GET /history
Get the history of all divisibility checks performed.
Response:
[
{
"number": 42,
"is_divisible_by_2": true,
"id": 1,
"created_at": "2025-05-14T12:34:56.789Z"
},
{
"number": 7,
"is_divisible_by_2": false,
"id": 2,
"created_at": "2025-05-14T12:35:01.234Z"
}
]
GET /health
Health check endpoint to verify the API is running.
Response:
{
"status": "healthy",
"api_version": "1.0.0",
"service": "Number Divisibility API"
}
Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
Running the API
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
FastAPI automatically generates interactive API documentation:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
Description
Languages
Python
96.9%
Mako
3.1%