Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnhof/fleek-responder
Response middleware for swagger documentation
https://github.com/johnhof/fleek-responder
Last synced: 20 days ago
JSON representation
Response middleware for swagger documentation
- Host: GitHub
- URL: https://github.com/johnhof/fleek-responder
- Owner: johnhof
- License: mit
- Created: 2017-02-06T23:31:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-10T00:18:28.000Z (almost 8 years ago)
- Last Synced: 2024-10-05T01:41:21.541Z (about 1 month ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fleek Responder
[![Build Status](https://travis-ci.org/fleekjs/fleek-responder.svg?branch=master)](https://travis-ci.org/fleekjs/fleek-responder)
Middleware for routing to controllers using [swagger](http://swagger.io/specification/) schema's.
Requirements:
- Node >= 6.0.0
- [fleek-context](https://github.com/fleekjs/fleek-context)# Usage
This package is to be used as middleware for [Koa2](https://github.com/koajs/koa/tree/v2.x) to bind responses for swagger documentation using `ctx.fleek.context` defined by [fleek-context](https://github.com/fleekjs/fleek-context) or an equivalent custom middleware.
```
npm install --save fleek-responder
```# Examples
For a swagger example, refer to the test [swagger json](https://github.com/fleekjs/fleek-responder/blob/master/tests/swagger.json)
```javascript
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
- [John Hofrichter](https://github.com/johnhof)
_Built and maintained with [](http://hart.com/) by the [Hart](http://hart.com/) team._