0.2.4 • Published 3 years ago

koa-springboot v0.2.4

Weekly downloads
20
License
MIT
Repository
github
Last release
3 years ago

koa-springboot

npm version last commit travis publish size license

feature

  • use decorator to build router
  • auto import controller
  • validate required params

install

npm i koa koa-router koa-springboot -S

demo

controller

// ...
@RequestMapping('/persons')
@ResponseBody
export default class Person {

  @GetMapping
  index() {
    return list;
  }

  @GetMapping('/:id')
  show(@PathVariable('id') id: string) {
    // ...
    return record;
  }

  @PostMapping
  create(@RequestBody body: any) {
    // ...
    return newRecord;
  }

  @PutMapping('/:id')
  update(@PathVariable('id') id: string, @RequestBody body: any) {
    // ...
  }

  @PatchMapping('/name/:id')
  patch(@PathVariable('id') id: string, @RequestBody body: any) {
    // ...
  }

  @DeleteMapping('/:id')
  destory(@PathVariable('id') id: string) {
    // ...
  }
}

app

// ...
@ControllerScan(__dirname, 'controller')
class App extends Application {
  // override init method to do you own logic
  // or not
  protected init() {
    this.app
    .use(bodyParser())
    .use(this.router.routes())
    .use(this.router.allowedMethods());
  }
}

new App().start();

see full demo here

reference

docs of spring mvc

0.2.4

3 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago