This is a simple Node.js API that can perform basic arithmetic operations (addition, subtraction, multiplication, and division) on two numbers passed as query parameters.
Getting Started These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Node.js
Start the API by running the following command: npm start The API will be running on http://localhost:8000
To use the calculator API, make a GET request to http://localhost:8000/calculator with the following query parameters:
operation: The type of operation to perform. Can be one of add, subtract, multiply, divide. num1: The first number. num2: The second number. For example, to add 5 and 3, make a GET request to http://localhost:8000/calculator?operation=add&num1=5&num2=3
The API will return a JSON object with a single key result that contains the result of the operation.
In case of invalid parameters or invalid operation, the API will return a JSON object with an error key and message.
This is a very simple example and it doesn't have any validation or error handling in place, you should add it in a production level implementation.
Node.js - JavaScript runtime Express.js - Web framework for Node.js
Alebiosu Gbolahan