REST API Development with Node.js by Fernando Doglio

REST API Development with Node.js by Fernando Doglio

Author:Fernando Doglio
Language: eng
Format: epub
ISBN: 9781484237151
Publisher: Apress


Once the model description is done, you add it to Swagger, as deomstrated in Listing 5-25.

// Load module dependencies.

const express = require("express")

, swagger = require("swagger-node-express")

, models = require('./models-definitions').models

//....

swagger.addModels(models)

Listing 5-25Letting Swagger Know About Your Models

Now you move on to the handler’s description, which contains fields describing each method, and the actual code to execute.

const swagger = require("swagger-node-express");

//Book handler's file

exports.listBooks = {

"spec": {

"description": "Returns the list of books",

"path": "/books.{format}",

"method": "GET",

"type": "Book",

"nickname": "listBooks",

"produces": ["application/json"],

"parameters": [swagger.paramTypes.query("sortBy","Sort books by title or isbn", "string")]

},

"action": (req, res) => {

//...

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.