Swagger driven API Development in Nodejs

Tool used: Visual Code

NPM Modules used:

  1. Swagger-tools
  2. js-yaml
  3. Express

Architecture description:

  1. Request first goes to the swagger validator.
  2. If the proper request(with supported URL, allowed headers, request body with required attributes) comes in, swagger validator fills the req object with swagger metadata attribute which will contain the operation id which we have specified in the swagger file.
  3. This valid request then reaches the controller.
  4. If an invalid request comes in, swagger validator will call the next(err). This err object will contain the reason of failure and the status code as well.
  5. Therefore it is very important to have an error handler middleware to handle the errors and send valid error response back to the client.

Suffering from Knowledge Quest

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store