A powerful and efficient RESTful API service that provides comprehensive mathematical properties and fascinating facts about numbers. Perfect for educational applications, math enthusiasts, or any project requiring number analysis.
- Get mathematical properties of a number (prime, perfect, Armstrong)
- Get the sum of digits
- Get interesting mathematical facts about the number
- CORS enabled
- JSON responses
- Input validation
- Error handling
GET /api/classify-number?number={number}
{
"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": "invalid_input",
"error": true
}- Go 1.21 or higher
- Git
- Clone the repository
git clone https://github.com/akinbo-emmanuel/numbersFactsAPI.git- Navigate to the project directory
cd numbersFactsAPI- Install dependencies
go mod tidy- Run the application
go run main.goThe server will start on http://localhost:8080
Using curl:
# Get properties of a number
curl "http://localhost:8080/api/classify-number?number=371"
# Get properties of a prime number
curl "http://localhost:8080/api/classify-number?number=17"
# Get properties of a perfect number
curl "http://localhost:8080/api/classify-number?number=28"Using JavaScript:
fetch('http://localhost:8080/api/classify-number?number=371')
.then(response => response.json())
.then(data => console.log(data));Using Python:
import requests
response = requests.get('http://localhost:8080/api/classify-number?number=371')
data = response.json()
print(data)This API can be easily deployed to Render.com for free. Follow these steps:
-
Create a Render account
-
Click "New +" and select "Web Service"
-
Connect your GitHub repository
-
Fill in the deployment details:
- Name:
numbersFactsAPI(or your preferred name) - Environment:
Docker - Branch:
main(or your default branch) - Region: Choose the closest to your users
- Instance Type: Free
- Name:
-
Click "Create Web Service"
The API will be automatically built and deployed. Render will provide you with a URL where your API is accessible.
No environment variables are required for basic functionality.
Replace your-render-url with your actual Render URL:
curl "https://your-render-url/api/classify-number?number=371"- Built with Go and Gin web framework
- Uses the Numbers API (numbersapi.com) for fun facts
- Implements CORS for cross-origin requests
- Response time < 500ms
- Supports all valid integers
The API implements proper error handling for:
- Invalid input types
- Missing parameters
- Network issues with external API
MIT License
Copyright (c) 2025 numbersFactsAPI
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.