A small example REST API using Python and Flask. This repository contains a minimal Flask app in src/main.py with a root endpoint and an Armstrong-number checker endpoint.
- GET
/— returns a simple greeting ("Hello, World!"). - GET
/armstrong/<int:n>— returns whethernis an Armstrong number as JSON.
- Python 3.8+ recommended. If you use Python 3.13, be aware some older package wheels may not support it; prefer 3.11 for maximum compatibility.
- Flask (install into the virtual environment used to run the app).
- Open a cmd prompt and change to the project folder.
- GET
/— returns a simple greeting ("Hello, World!"). - GET
/armstrong/<int:n>— returns whethernis an Armstrong number. - GET
/palindrome/<int:n>— returns whethernis a palindrome (supports ordinary integers, including 4-digit numbers like1221). - GET
/sum?a=2&b=3— returns the sum ofaandb(query params). - POST
/sum— accepts JSON{ "a": <int>, "b": <int> }and returns the sum. - GET
/avg?a=2&b=3— returns the average ofaandb(query params).
- Python 3.8+ recommended. If you use Python 3.13, some wheels may not be available; prefer 3.11 if you run into install problems.
- See
requirements.txtfor the minimal dependencies to run and test the project.
- (Optional) Create and activate a virtual environment:
python -m venv .venv
.venv\Scripts\activate.bat- Install dependencies:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt- Run the app:
python src\main.pyBy default the app runs on http://127.0.0.1:5000.
Root
curl http://127.0.0.1:5000/
# {"message":"Hello, World!"}Armstrong
curl http://127.0.0.1:5000/armstrong/153
# {"Number":153,"Armstrong":true,"Server IP":"127.0.0.1:5000"}Palindrome
curl http://127.0.0.1:5000/palindrome/1221
# {"Number":1221,"Palindrome":true,"Server IP":"127.0.0.1:5000"}Sum (GET, query params)
curl "http://127.0.0.1:5000/sum?a=2&b=3"
# {"a":2,"b":3,"result":5}Sum (POST, JSON body)
curl -H "Content-Type: application/json" -d "{\"a\":2,\"b\":3}" http://127.0.0.1:5000/sum
# {"a":2,"b":3,"result":5}Average (direct function)
from src.main import avg
print(avg(2, 3)) # 2.5Tests are in the tests/ folder and use pytest.
Install test requirements and run tests:
python -m pip install -r requirements.txt
python -m pytest -q
