Create REST APIs with swagger and strong-loop

Gone are the days when you needed to write code and develop REST API to share detailed documentation with end Users.

Now is the time when we can visualize and design and even interact with the API’s resources without having any of the implementation logic in place.

Good to start with. And the icing on the cake is that we can generate the implementation code in more than 25 programing languages based on above design specs.

Welcome to swagger editor.

It allows you to edit, define and simultaneously visualize the behavior of your REST APIs before they are even developed.

Benefit in going this way is that you can keep changing the contract quickly until it gets finalized and then you can start real development. This tool can be used as boiler plate before starting a new project in the language of your choice.

If you wish to develop them using strong-loop, you can get a quick-start using loopback:swagger. (You don’t need below steps for other than strong-loop)

Below are the steps:

  1. install loopback
  2. Run below in terminal
    • slc loopback:swagger
  3. What’s the name of your application? swagger-loop
    • Which version of LoopBack would you like to use? 2.x (long term support)
    • What kind of application do you have in mind? ❯ empty-server
  4. npm i loopback-swagger
  5. cd swagger-loop
  6. File –> convert and save as json from below URL
    • https://editor.swagger.io/
  7. save the above json as swagger.json (or any name of your choice)
  8. slc loopback:swagger
  9. Enter the swagger spec url or file path: swagger.json
  10. Successful completion of above command should generate the strongloop code for the API based on the swagger specification defined in the swagger.json

References:

https://loopback.io/doc/en/lb3/Swagger-generator.html

https://docs.strongloop.com/display/public/LB/Swagger%20generator

https://www.npmjs.com/package/loopback-swagger

Co-Authored by:

Balram Singh

Note: This Article was earlier posted at

https://www.linkedin.com/pulse/create-rest-apis-swagger-strong-loop-narendra-mandiwal/