Skip to content

A middleware which can let you send your response easier

License

Notifications You must be signed in to change notification settings

songchengen/koa2-response

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa2-response

A middleware which can let you send your response easier

Install

npm install koa2-response

Usage

    const koa = require('koa');
    const app = new koa();
    const router = require('koa-router')();
    const response = require('koa2-response');
    
    const code = {
      UNKNOWN_ERROR: [1, 'Sorry, you seem to have encountered some unknown errors.']
    }
    
    router
      .get('/', (ctx, next) => {
        response.success(ctx, {
          name: 'test'
        })
      })
      .get('/error_test', (ctx, next) => {
         response.error(ctx, code.UNKNOWN_ERROR);
      })
    
    app.use(router.routes());
    app.use(router.allowedMethods());
    
    app.listen(3000);
    
    console.log(`Server is running on port 3000`);

Licences

MIT

About

A middleware which can let you send your response easier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%