A RESTful API that analyzes numbers and returns their mathematical properties along with interesting facts.
number-classification-api/ ├── app.py # Application entry point and route ├── services/ │ └── number_api_service.py # Business logic ├── utils/ │ ├── constants.py # Configuration constants │ └── number_properties.py # Mathematical utilities ├── requirements.txt └── README.md - Determines if a number is prime
- Checks if a number is perfect
- Identifies Armstrong numbers
- Calculates digit sum
- Classifies numbers as even/odd
- Fetches fun facts from the Numbers API
- CORS enabled
- Handles invalid input gracefully
- Python 3.8+
- Flask
- Flask-CORS
- Requests
- gunicorn
-
Clone the repository:
git clone https://github.com/EmmyAnieDev/hngx-stage1-number-classifier-api.git cd hngx-stage1-number-classifier-api -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Start the server:
python app.py- The API will be available at
http://localhost:8000
http://localhost:8000/api/classify-number?number=5{ "number": 5, "is_prime": true, "is_perfect": false, "properties": [ "armstrong", "odd" ], "digit_sum": 5, "fun_fact": "5 is the third prime number." }{ "number": "letter", "error": true }{ "number": "null", "error": true }{ "number": "", "error": true }The API is deployed on Railway and can be accessed at:
https://number-classifier-api-production.up.railway.app/ To test the full URL with the parameter:
curl "https://number-classifier-api-production.up.railway.app/api/classify-number?number=5"