This project is a calculator API where users can use the endpoint to perform basic mathematical operations such as addition, subtraction, multiplication, and division. Express was used in the development of the API using Node.js and MongoDB.
To install and run the API Calculator on another machine, follow the steps below:
- Clone the repository from GitHub:
git clone https://github.com/NurMustafaM/API-Calculator.git
- Navigate to the project directory:
cd API-Calculator
- Install the required dependencies using npm:
npm install
The configuration for the API Calculator is managed through the config/default.json
file. It contains settings related to Swagger generation and the server's port and timeout. You can customize these settings as per your requirements.
{
"swagger": {
"generatefile": true,
"getDateFormatted": false
},
"server": {
"port": 8080,
"timeout": 120000
}
}
generatefile
: Set this totrue
if you want to generate Swagger JSON files with date in the filename. Set it tofalse
if you want Swagger files without a date in the filename.getDateFormatted
: Set this totrue
if you want to include the date in Swagger JSON filenames. This flag is only effective whengeneratefile
is set totrue
.
Once the installation and configuration steps are complete, you can start the API Calculator with the following command:
npm start
The API will be accessible at http://localhost:8080
. You can use this URL to make API requests.
If the Swagger JSON file is generated (based on the configuration), you can access the Swagger UI documentation by visiting:
- Swagger UI:
http://localhost:8080/api-docs
If the Swagger file is not found (based on the configuration), the Swagger UI will not be available, but the API will still work as expected.
The API Calculator provides the following routes:
- POST
/add
: Route to add two numbers. Example:http://localhost:8080/add
- GET
/subtract/:a/:b
: Route to subtract two numbers. Example:http://localhost:8080/subtract/10/5
- GET
/multiply/:a/:b
: Route to multiply two numbers. Example:http://localhost:8080/multiply/2/3
- GET
/divide/:a/:b
: Route to divide two numbers. Example:http://localhost:8080/divide/10/2
This project is licensed under the ISC License. See the LICENSE
file for details.
This project was created by Nor.
Please refer to the GitHub repository for more information and updates.
If you need assistance or have any questions about the project, you can find additional information in the following resources:
- Express.js documentation: https://expressjs.com/
- Documentation on specific JavaScript functions and operators: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/isFinite, https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
- Node.js documentation: https://nodejs.org/
- MongoDB documentation: https://www.mongodb.com/docs/
Nor Mustafa Mohamad
Feel free to contact me if you have any questions or suggestions for the project.