
- 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)
85 lines
1.3 KiB
Markdown
85 lines
1.3 KiB
Markdown
# 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:**
|
|
```json
|
|
{
|
|
"number": 42,
|
|
"is_divisible_by_2": true
|
|
}
|
|
```
|
|
|
|
### POST /divisibility
|
|
|
|
Check if a number is divisible by 2 using a JSON request body.
|
|
|
|
**Request Body:**
|
|
```json
|
|
{
|
|
"number": 42
|
|
}
|
|
```
|
|
|
|
**Response:**
|
|
```json
|
|
{
|
|
"number": 42,
|
|
"is_divisible_by_2": true
|
|
}
|
|
```
|
|
|
|
### GET /health
|
|
|
|
Health check endpoint to verify the API is running.
|
|
|
|
**Response:**
|
|
```json
|
|
{
|
|
"status": "healthy",
|
|
"api_version": "1.0.0",
|
|
"service": "Number Divisibility API"
|
|
}
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository
|
|
2. 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` |