FastAPI Starter Application
A simple FastAPI application with a hello world endpoint and a calculator endpoint.
Installation
- Create a virtual environment:
python -m venv venv- Activate the virtual environment:
# Windows (PowerShell)
.\venv\Scripts\Activate.ps1
# Windows (CMD)
.\venv\Scripts\activate.bat
# Linux/Mac
source venv/bin/activate- Install dependencies:
pip install -r requirements.txtRunning the Application
Start the development server:
uvicorn main:app --reloadThe API will be available at http://localhost:8000
API Endpoints
1. Hello World
- URL:
/ - Method: GET
- Response:
{
"message": "Hello World"
}2. Calculator
- URL:
/calculator - Method: POST
- Request Body:
{
"operation": "add",
"num1": 10,
"num2": 5
}- Supported Operations:
add,subtract,multiply,divide - Response:
{
"operation": "add",
"num1": 10,
"num2": 5,
"result": 15
}Interactive API Documentation
Once the server is running, you can access:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
Example Usage
# Hello World
curl http://localhost:8000/
# Calculator - Addition
curl -X POST http://localhost:8000/calculator \
-H "Content-Type: application/json" \
-d '{"operation": "add", "num1": 10, "num2": 5}'
# Calculator - Division
curl -X POST http://localhost:8000/calculator \
-H "Content-Type: application/json" \
-d '{"operation": "divide", "num1": 20, "num2": 4}'On this page
Contributors
Created January 12, 2026
Updated January 12, 2026