
- Implemented FastAPI application with divisibility checking - Added endpoints for checking divisibility via GET and POST - Added health endpoint - Created requirements.txt - Updated README with API documentation generated with BackendIM... (backend.im)
1.3 KiB
1.3 KiB
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
- 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 /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
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