Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/potatogopher/koa-response-handler
Lightweight response handler for Koa JS
https://github.com/potatogopher/koa-response-handler
es6 javascript koa-router koajs nodejs
Last synced: about 1 month ago
JSON representation
Lightweight response handler for Koa JS
- Host: GitHub
- URL: https://github.com/potatogopher/koa-response-handler
- Owner: potatogopher
- Created: 2017-06-01T18:32:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-12T15:54:00.000Z (about 6 years ago)
- Last Synced: 2024-10-31T08:42:29.346Z (about 1 month ago)
- Topics: es6, javascript, koa-router, koajs, nodejs
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-koa - koa-response-handler - lightweight response handler for koa (Middleware)
README
# koa-response-handler
Response handler middleware for [koa](https://github.com/koajs/koa).## Installation
```js
$ yarn add koa-response-handler
```
## Example
```js
import Koa from 'koa'
import Router from 'koa-router'
import responseHandler from 'koa-response-handler'const app = new Koa()
const router = new Router()app
.use(responseHandler({ contentType: 'application/json' }))
.use(router.routes())
.use(router.allowedMethods())router.get('/:id', function async (ctx, next) {
let data = {id: 1, hello: 'world' }if (ctx.params.id !== data.id) {
ctx.response.notFound()
return
}ctx.response.ok(data)
})
```## License
MIT