The Number Classification API is a RESTful service that accepts a number and returns interesting mathematical properties about it, along with a fun fact from the Numbers API.
- Check if a number is prime.
- Check if a number is perfect.
- Check if a number is an Armstrong number.
- Determine if a number is even or odd.
- Calculate the sum of its digits.
- Fetch a fun fact about the number.
- Returns structured JSON responses.
- Handles error validation and incorrect input.
- Fully deployed on Render.
- Node.js (Express.js)
- TypeScript
- Axios (for external API requests)
- Helmet & CORS (for security)
- Render (for deployment)
number-classification-api/
│── src/
│ ├── constants/
│ │ ├── env.ts # Environment variables
│ │ ├── routes.ts # API route constants
│ ├── core/
│ │ ├── number/
│ │ │ ├── number.controller.ts # Number classification logic
│ │ │ ├── number.routes.ts # API routes
│ ├── utils/
│ │ ├── logger.utils.ts # Logger utility
│── index.ts # Main Express server file
│── tsconfig.json # TypeScript configuration
│── package.json # Project dependencies & scripts
│── .env # Environment variables
git clone https://github.com/ricky-ultimate/number-classification-api.git
cd number-classification-api
npm install
Create a .env
file and add:
PORT=5001
npm run dev
Open your browser or use curl
:
curl http://localhost:5001/api/classify-number?number=371
Expected Response:
{
"number": 371,
"is_prime": false,
"is_perfect": false,
"properties": ["armstrong", "odd"],
"digit_sum": 11,
"fun_fact": "371 is a narcissistic number."
}
GET /api/classify-number?number=28
{
"number": 28,
"is_prime": false,
"is_perfect": true,
"properties": ["even"],
"digit_sum": 10,
"fun_fact": "28 is the 2^{nd} perfect number."
}
{
"number": "abc",
"error": true
}