Skip to content

potatogopher/koa-response-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-response-handler

Response handler middleware for koa.

KoaJs Slack

Installation

$ yarn add koa-response-handler

Example

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

About

Lightweight response handler for Koa JS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •