A REST API that analyzes numbers and returns their mathematical properties along with interesting facts. The API takes a number as a query parameter and returns various properties like whether it's prime, perfect, Armstrong, even/odd, along with the sum of its digits and a fun mathematical fact.
- Number classification (prime, perfect, Armstrong)
- Basic properties (odd/even)
- Digit sum calculation
- Fun mathematical facts from Numbers API
- Input validation
- CORS support
- JSON responses
GET /classify-number
The API is deployed and accessible at:
https://legislative-pierrette-kenward-dc9303b6.koyeb.app/api/classify-number?number=<your-number>
Example:
https://legislative-pierrette-kenward-dc9303b6.koyeb.app/api/classify-number?number=371
| Parameter | Type | Required | Description |
|---|---|---|---|
| number | integer | Yes | Number to analyze |
{
"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"
}{
"number": "alphabet",
"error": true
}The properties field can have the following combinations:
["armstrong", "odd"]- for Armstrong numbers that are odd["armstrong", "even"]- for Armstrong numbers that are even["odd"]- for non-Armstrong odd numbers["even"]- for non-Armstrong even numbers
- Framework: Django REST Framework
- External APIs: Numbers API (http://numbersapi.com)
- Response Time: < 500ms
- CORS: Enabled for all origins
- Hosting: Deployed on Koyeb
- Clone the repository
git clone https://github.com/Kenward-dev/Number-Classification-API.git
cd Number-Classification-API- Create and activate virtual environment
python -m venv venv
source venv/bin/activate # For Unix/macOS
venv\Scripts\activate # For Windows- Install dependencies
pip install -r requirements.txt- Start the development server
python manage.py runserverThe API is deployed and accessible at:
https://legislative-pierrette-kenward-dc9303b6.koyeb.app/api/
For production deployment:
- Set
DEBUG=Falsein settings - Configure your production database
- Set up proper CORS settings
- Use a production-grade server (e.g., Gunicorn)
- Set up proper error logging
- 400 Bad Request: Invalid input (non-integer or missing number)
- 503 Service Unavailable: Numbers API service unavailable
- 500 Internal Server Error: Unexpected server errors
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Numbers API for providing mathematical facts
- Django REST Framework for the API framework