Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Number Classification API

This is a simple API built with Go (Golang) that classifies a given number and provides various properties, including:

  • Whether the number is prime
  • Whether the number is perfect
  • Whether the number is an Armstrong number
  • Whether the number is even or odd
  • The sum of its digits
  • A fun fact fetched from an external API

Features

  • Provides multiple classifications for a number.
  • Fetches a fun fact about the number from the Numbers API.
  • Returns data in JSON format.
  • Handles errors gracefully (e.g., invalid input).

Table of Contents

Prerequisites

  • Go 1.16 or higher.
  • An internet connection to access the Numbers API for fun facts.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/number-classifier-api.git
  2. Navigate into the project directory:

cd number-classifier-api
  1. Initialize Go modules (if you haven't already):
go mod init number-classifier-api
  1. Install dependencies:
go mod tidy
  1. Running the API Run the server using the following command:
go run main.go

The server will start and listen on port 8080 by default.

You can access the API by sending requests to:

http://localhost:8080/api/classify-number?number=<your-number>

Example

For example, to classify the number 371:

http://localhost:8080/api/classify-number?number=371

Example Request

GET /api/classify-number?number=371

Example 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" }

Example Response (400 Bad Request)

If an invalid input is provided (e.g., a string instead of a number): { "number": "alphabet", "error": true }

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages