Skip to content

A powerful Go-based REST API that provides mathematical properties and fascinating facts about numbers. Get instant access to number classifications, properties like prime/perfect/Armstrong numbers, digit sums, and interesting mathematical facts. Built with Go and Gin framework, featuring robust error handling and CORS support.

Notifications You must be signed in to change notification settings

akinbo-emmanuel/numbersFactsAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numbersFactsAPI

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.

Features

  • 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

API Specification

Endpoint

GET /api/classify-number?number={number}

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": "invalid_input",
    "error": true
}

Getting Started

Prerequisites

  • Go 1.21 or higher
  • Git

Installation

  1. Clone the repository
git clone https://github.com/akinbo-emmanuel/numbersFactsAPI.git
  1. Navigate to the project directory
cd numbersFactsAPI
  1. Install dependencies
go mod tidy
  1. Run the application
go run main.go

The server will start on http://localhost:8080

Usage Examples

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)

Deployment

This API can be easily deployed to Render.com for free. Follow these steps:

  1. Create a Render account

  2. Click "New +" and select "Web Service"

  3. Connect your GitHub repository

  4. 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
  5. Click "Create Web Service"

The API will be automatically built and deployed. Render will provide you with a URL where your API is accessible.

Environment Variables

No environment variables are required for basic functionality.

Testing the Deployed API

Replace your-render-url with your actual Render URL:

curl "https://your-render-url/api/classify-number?number=371"

Technical Details

  • 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

Error Handling

The API implements proper error handling for:

  • Invalid input types
  • Missing parameters
  • Network issues with external API

License

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.

About

A powerful Go-based REST API that provides mathematical properties and fascinating facts about numbers. Get instant access to number classifications, properties like prime/perfect/Armstrong numbers, digit sums, and interesting mathematical facts. Built with Go and Gin framework, featuring robust error handling and CORS support.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published