Tutorial:API Calculator with swagger
Swagger is an Interface Description Language for describing RESTful APIs expressed using JSON. Swagger is used together with a set of open-source software tools to design, build, document, and use RESTful web services. Swagger includes automated documentation, code generation (into many programming languages), and test-case generation.
To start this tutorial you must have some knowlege of nodejs, if not check my previous tutorials.
First create a folder where our api is created, then on nojs cpromps change the directory to that folder and type the following commands:
npm init
npm install express
npm i swagger-ui-express -S
After that crate a the index.js file and write the following code:
(this file have already the route part)
After that create a file named swagger.json and write the following code:
To get our server up type:
node index.js
Anf the open http://localhost:8001/api-docs/ on your browser and the output should look like this:
To test our api click on Try Out and the output should look like this:
The click on Execute, and tehe result should appear on the field Response body.
This tutorial is on my github: