The Number Classification API is a web service that accepts a number as input and returns interesting mathematical properties about it, along with a fun fact.
- Determines if a number is prime or perfect.
- Identifies properties such as odd, even, or Armstrong number.
- Calculates the sum of digits.
- Fetches a fun fact about the number using the Numbers API.
- Programming Language: Python
- Framework: FastAPI / Flask (depending on your implementation)
- Deployment: Hosted on a publicly accessible endpoint
- Version Control: Git & GitHub
- Data Handling: Numbers API
- Security: CORS enabled
Endpoint:
GET /api/classify-number?number={number}
Request Parameters:
number
(integer) - The number to classify
Success Response (200 OK):
{
"number": 371,
"is_prime": false,
"is_perfect": false,
"properties": ["armstrong", "odd"],
"digit_sum": 11,
"fun_fact": "371 is an Armstrong number because 3^3 + 7^3 + 1^3 = 371"
}
Error Response (400 Bad Request):
{
"number": "alphabet",
"error": true
}
Ensure you have the following installed:
- Python 3.8+
- Git
- Virtual Environment (optional but recommended)
- Clone the Repository
git clone https://github.com/Teejee001/HNG12-Backend--Number-Classification-API.git
cd HNG12-Backend--Number-Classification-API
- Set up a Virtual Environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows, use 'venv\Scripts\activate'
- Install Dependencies
pip install -r requirements.txt
- Run the API
uvicorn app:app --host 0.0.0.0 --port 8000 --reload # For FastAPI
# OR
python app.py # If using Flask
- The API is deployed to Your Public Endpoint
- Uses CORS handling for cross-origin requests
You can test the API using:
- Postman
- cURL
- Your Web Browser
curl -X GET "https://your-deployed-api.com/api/classify-number?number=371"
Contributions are welcome! To contribute:
- Fork the repository
- Create a new branch (
feature-xyz
) - Commit your changes
- Push to your fork
- Create a pull request
This project is licensed under the MIT License . ##Resources Fun fact API: http://numbersapi.com/#42 https://en.wikipedia.org/wiki/Parity_(mathematics)