0.4.0 • Published 7 years ago

@axetroy/kor v0.4.0

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

Kor

Greenkeeper badge Build Status Dependency License Prettier Node npm version FOSSA Status

Integration Koa + Koa-router with graceful API

Features

  • Base on Koa@2
  • Integration Koa-router
  • Graceful Router define
  • Static file (unnecessary)
  • Auto Load View Template(unnecessary)

Installation

npm install @axetroy/kor -g

Usage

const Kor = require('@axetroy/kor');
const userRoute = Kor.Router();
const commonRoute = Kor.Router();

userRoute
  .get('/', ctx => {
    ctx.body = `hey! It's user API`;
  })
  .head('/auth', ctx => {
    ctx.body = 'Auth success!';
  })
  .get('/info', ctx => {
    ctx.body = 'here is your user information';
  })
  .post('/register', ctx => {
    ctx.body = 'register success!';
  })
  .put('/info', ctx => {
    ctx.body = 'Update user information success!';
  })
  .delete('/addFriend/:username', ctx => {
    ctx.body = `Add friend ${ctx.params.username} success!`;
  });

commonRoute
  .get('/', ctx => {
    ctx.body = `hey! It's common API`;
  })
  .get('/now', ctx => {
    ctx.body = Date.now();
  });

const app = new Kor();

app
  .use((ctx, next) => {
    // an middleware
    next();
  })
  .all('/all', ctx => {
    ctx.body = `This is all method: ${ctx.request.method}`;
  })
  .get('/say/:word', ctx => {
    ctx.body = `Hello ${ctx.params.word}`;
  })
  .route('/api/v1/common', commonRoute)
  .route('/api/v1/user', userRoute)
  .use(function NotFound(ctx) {
    ctx.body = '404 Not Found';
  })
  .listen(8080, function() {
    console.info(`Listen on 8080`);
  });

More Examples

Contributing

git clone https://github.com/axetroy/kor.git
cd ./kor
yarn

You can flow Contribute Guide

Contributors

Axetroy💻 🐛 🎨

License

The MIT License

FOSSA Status

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago