node.js tutorial: API calculator using Swagger
In this tutorial, you will learn how to make a calculator API with elementary arithmetic operations, using Swagger.
Swagger is an interface description language for describing RESTful APIs expressed using JSON and is used in conjunction with a set of Open Source software tools to design, build, document and use RESTful web services.
So let’s start the tutorial!!
1st step: Open the command line and use the following commands to create the project.
After that, we will indicate the requested parameters.
2nd step: Install the necessary dependencies (express and swagger-ui)
npm install express
npm install swagger-ui-express --save
3rd step: Create index.js and swagger.json files
4th step: Place the following code in the index.js file
5th step: Place the following code in the swagger.json file where we are going to create the elementary arithmetic operations (sum, subtraction, multiplication and division)
Last step: Run the project
Open the address http://localhost:8888/calculator/
And test the operations