0.1.8 • Published 5 years ago
@jujorie/swabe v0.1.8
Swagger Backend - Swabe
Easy create a backend using swagger
Table of contents
Requirements
Dependencies
- swagger-tools - For creating routes
- connect - For server middlewares
Installation
$ npm install -S @jujorie/swabe
Basic Usage
sample/server.js
'use strict';
const connect = require('connect');
const app = connect();
const http = require('http');
const {resolve} = require('path');
const {SwaggerServer} = require('@jujorie/swabe');
SwaggerServer.create()
.description('Basic Sample server')
.version('0.1.0')
.title('Basic API')
.controller(resolve(__dirname, './controller.js'))
.initialize(app)
.then(() => {
http.createServer(app).listen(8080, () => {
console.log('Server is up on 8080');
});
})
.catch((err) => {
console.log(err.toString());
});
sample/controller.js
'use strict';
const {SwaggerAction} = require('@jujorie/swabe');
module.exports = SwaggerAction
.create()
.define('getInfo')
.requestHandler(SwaggerAction.jsonResponse(() => {
return 'hello';
}))
.getSwaggerAction();
this will produce a end point at http://localhost:8080/sample/info
Examples
you may check others examples at here
Commands
For development once cloned the repository can use this npm commands
Test
Run all the tests with coverage analysis
$ npm run test
Test Only
Run all the tests without coverage analysis
$ npm run test:only
Lint
Run the linter for the code
$ npm run lint
doc
Run the document generator
$ npm run doc