The swagger module provides tools for designing and building Swagger-compliant APIs entirely in Node.js. It integrates with popular Node.js servers, including Express, Hapi, Restify, and Sails, as well as any Connect-based middleware. With swagger, you can specify, build, and test your API from the very beginning, on your laptop. It allows you to change and iterate your design without rewriting the logic of your implementation.
alt text
Remember, one great thing about this approach is that all of the Swagger validation logic is handled for you, and all of the routing logic is managed through the Swagger configuration. You don't have to code (or recode!) any of that stuff yourself.
Your swagger API in five steps
1. Install the swagger module
Install using npm. For complete instructions, see the install page.
$ npm install -g swagger
2. Create a new swagger project
Use the CLI to create and manage projects. Learn more on the quick start page.
$ swagger project create hello-world
3. Design your API in the Swagger Editor
The interactive, browser-based Swagger Editor is built in. It provides Swagger 2.0 validation and endpoint routing, generates docs on the fly, and consumes easy-to-read YAML.
$ swagger project edit
screenshot of project editor
4. Write controller code in Node.js
Code your API's business logic in Node.js.
function hello(req, res) {
var name = req.swagger.params.name.value || 'stranger';
var hello = util.format('Hello, %s!', name);
res.json({ "message": hello });
}
If you look at the Swagger file in the editor (shown in step 3 above), the x-swagger-router-controller element (line 17 in the editor screenshot) specifies the name of the controller file associated with the /hello path. For example:
paths:
/hello:
x-swagger-router-controller: hello_world
Controller source code is always placed in ./api/controllers. So, the controller source file for this project is ./api/controllers/hello_world.js.
The operationId element specifies which controller function to call. In this case (line 19), it is a function called hello. Learn more.
5. Run the server
Run the project server.
$ swagger project start
Now, call the API!
It just works!
$ curl http://127.0.0.1:10010/hello?name=Scott
{ "message": "Hello, Scott!" }
Installing the swagger module
See the Installing swagger for details.
Using the swagger module
Go to the swagger module doc page. It includes all the information you need to get started.
#nodejs #mongodb #mongoose #mongodbatlas #cloudcomputing
Mongodb Atlas Cloud link : https://cloud.mongodb.com/
Mongoose : https://mongoosejs.com/docs/guide.html
Source Code Github : https://github.com/firdousalam/Nodejs...
Official Express Documentation: https://expressjs.com/
Official Mongoose Documentation: https://mongoosejs.com/docs/guide.html
Part 1 : • Nodejs Hindi Tutorial Part 1 | Nodejs...
Part 2 : • Node.js Tutorial Part 2 | Node.js Tu...
Part 3 : • Nodejs Tutorial Part 3 | Struggling t...
Part 4 : • Nodejs Tutorial Part 4 | Express Rou...
Part 5 : • Connect #Mongodb using Node JS and m...
Part 8 : • AnyBody Can Write Industry Standard N...
Part 9 : • Easy Way to debug nodejs code in vsco...
Part 10 : • How to Join Two Table(Collection) In ...
Part 11 : • #Nodejs #Logger | Nodejs Tutorial Par...
Part 12 : • Nodejs Cron Job | How to run cron job...
Part 13 : • Nodejs PDF Generator | How to Generat...
Part 14 : • How to Read Write File In Nodejs | No...
Part 15 : • Nodejs Authentication Using JWT | Nod...
Part 16 : • Nodejs Swagger | How To Add Swagger f...
Nodejs Code Structure : • Easy Way to debug nodejs code in vsco...
Nodejs Debug Using VSCode : • Easy Way to debug nodejs code in vsco...
#node #nodejs #leelawebdev
⭐️ Tags ⭐️
Node.js Command Line Tutorial
Introduction to Node.js
Node.js vs Browser
Node.Js Crash Course
⭐️ Hashtags ⭐️
#nodejs #beginners #tutorial #nodejscodestructure #expressStructure #nodejsTutorialHindi #NodejsHindi #Node.jsHindiTutorial
#nodejs
#experiencedeveloper
#Interview
#node
#node.js
#software
#engineer
#question
#git
#nodejs
#angularjs
#javascript
#TCS
#CTS
#IBM
#WIPRO
#INFOSYS
#GATEWAY GROUP
#MICROSOFT
#NAGARRO
#ORACLE
#DELL
#CISCO
#MPHASIS
#TREDENCE
#ZEBRA
#REDISYS
#DKATALIS
#HAUSEN
#angularjs
#angular
Please support my channel and don't forget to subscribe and like my videos and channel
Gmail : [email protected]
Facebook Link : / firdous.alam2058
Instagram Link : / firdous.alam2058
LinkedIn Link : / firdous-alam-09421139
Twitter Link : / vicky2firdous