- Project Overview
- Features
- Installation Instructions
- API Endpoints
- Testing Instructions
- Technologies Used
- Contribution Guidelines
- Acknowledgments
The Number Classification API provides a set of endpoints to classify numbers based on several mathematical properties, such as prime, perfect, Armstrong, odd, and even. In addition, the API fetches a fun fact related to the number from the Numbers API.
- Prime Number Check: Determines whether the number is prime.
- Perfect Number Check: Determines whether the number is perfect.
- Armstrong Number Check: Determines whether the number is an Armstrong number.
- Odd or Even Check: Classifies the number as odd or even.
- Digit Sum Calculation: Calculates the sum of the digits of the number.
- Fun Fact Retrieval: Fetches a fun fact related to the number using an external API.
Follow the steps below to get this project up and running on your local machine.
Before getting started, ensure that you have the following software installed on your machine:
Start by cloning the repository to your local machine:
git clone https://github.com/G4EVA-dev/Number-Classification-API
cd number-classification-api
Use npm to install the project’s dependencies:
npm install
Create a .env
file in the root of the project directory and set up the following variables:
PORT=3000
Start the development server:
npm run dev
The server will be available at http://localhost:3000.
This endpoint takes a number and classifies it based on various properties. It also returns a fun fact related to the number.
number
(required): The number to classify.
{
"number": 153,
"is_prime": false,
"is_perfect": false,
"properties": ["armstrong", "odd"],
"digit_sum": 9,
"fun_fact": "153 is a narcissistic number."
}
number
: The number provided in the query.is_prime
: Boolean value indicating whether the number is prime.is_perfect
: Boolean value indicating whether the number is perfect.properties
: An array of properties such asarmstrong
,odd
,even
.digit_sum
: The sum of the digits of the number.fun_fact
: A fun fact related to the number fetched from an external API.
-
400 Bad Request: If the
number
query parameter is missing or invalid.Example response:
{ "number": "abc", "error": true }
-
500 Internal Server Error: If there’s an error processing the request.
Example response:
{ "error": "Internal Server Error" }
To ensure the quality and reliability of the API, you can run the tests provided in this project.
To run the tests for the project, use the following command:
npm run test
This will run the unit tests for the core functions and API endpoints. Make sure that you have installed all dependencies first.
- Node.js: A JavaScript runtime built on Chrome's V8 JavaScript engine.
- Express: A fast, unopinionated, minimalist web framework for Node.js, used to build the API.
- Axios: A promise-based HTTP client for making requests to external APIs (used to fetch fun facts).
- TypeScript: A typed superset of JavaScript that compiles to plain JavaScript. It provides static type checking, making the code more reliable and maintainable.
- CORS: Middleware to enable cross-origin resource sharing, allowing requests from different origins.
We welcome contributions to the Number Classification API project! If you would like to contribute, please follow these steps:
- Fork the repository to your own GitHub account.
- Clone the forked repository to your local machine.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -am 'Add new feature'
). - Push your changes to your forked repository (
git push origin feature-branch
). - Open a pull request to the main repository, describing the changes you made and why they are beneficial.
This project is licensed under the MIT License - see the LICENSE file for details.
- The Numbers API: Used to fetch fun facts about numbers.
- Express: For making web application development simple and fast.
- TypeScript: To help ensure the quality and maintainability of the project codebase.
- Fun Fact API
- Wikipedia Math Parity
For more information, feel free to open an issue or contact the project maintainers. Contributions, issues, and suggestions are always welcome!
For the latest updates and features, check out the GitHub repository.