Skip to content

johnhof/fleek-responder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fleek Responder

Build Status

Middleware for routing to controllers using swagger schema's.

Requirements:

Usage

This package is to be used as middleware for Koa2 to bind responses for swagger documentation using ctx.fleek.context defined by fleek-context or an equivalent custom middleware.

npm install --save fleek-responder

Examples

For a swagger example, refer to the test swagger json

const Koa = require('koa');
const fleekCtx = require('fleek-context');Â
const fleekResponder = require('fleek-responder');

const SWAGGER = require('./swagger.json');

let app = new Koa();

app.use(fleekCtx(SWAGGER));

app.use(fleekResponder({
  strict: true, // Force all responses to validate against the path definitions
  camelCase: true, // Convert shortcuts to camelcase
  default: {
    fallback: 'NotFound'
    downstream: true, // Run default response application on the way down the middleware chain
    upstream: true // Run default response application on the way up the middleware chain
  }
}));

app.use((ctx, next) => {
  console.log(ctx.body); // => { code: 404, error: { description: "not found" } }
  ctx.fleek.response.success({
    data: {
      hello: 'world'
    }
  });
  console.log(ctx.body); // => { code: 200, data: { hello: 'world' } }
  return next();
});

app.listen(3000);

Documentation

TODO

Authors

Built and maintained with by the Hart team.

About

Response middleware for swagger documentation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published