0.0.8 • Published 7 years ago

koa-reply v0.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

koa-reply

Middleware for Koa that adds some common methods to the Koa response.

npm version npm download

Install

$ npm i koa-reply -S

Description

There are method and corresponding status code:

  • OK: 200
  • Created: 201
  • BadRequest: 400
  • UnAuthorized: 401
  • Forbidden: 403
  • NotFound: 404
  • InternalServerError: 500

    Or you can add your optiosns:

    const koa = require('koa');
    const reply = require('koa-reply');
    
    const app = koa();
    
    app.use(reply({
      myMethod: code
      //...
    }));
    //...

Usage

Check the example

const koa = require('koa');
const router = require('koa-router')();
const reply = require('koa-reply');

const app = koa();
// add reply middleware on top level
app.use(reply());

// test router
router.get('/', function* () {
  this.response.OK = 'hello world';
});
router.get('/404', function* () {
  this.response.NotFound = 'Not Found'
});
router.post('/create', function* () {
  this.response.Created = 'success';
});
// ... others

app.use(router.routes());
app.use(router.allowedMethods());

app.listen(process.env.PORT || 3000, function() {
  console.log('Using `replt` middleware in test');
});
0.0.8

7 years ago

0.0.6

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago