0.12.1 • Published 1 year ago

@mhio/koa-api-handle v0.12.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@mhio/koa-api-handle

A Koa API Handler to do all the request heavy lifting, so you just write logic

Higher level use from: https://github.com/mhio/node-koa-api

Install

yarn add @mhio/koa-api-handle
npm install @mhio/koa-api-handle

Usage

API docs

const Koa = require('koa')
const Router = require('koa-router')
const {KoaApiHandle} = require('@mhio/koa-api-handle')

class MyHandler {
  
  static get error_message(){
    return 'Failure'
  }

  static async ok(ctx){
    return {
      ok: true,
      request_id, ctx.state.request_id,
    }
  }

  static async other(){
    return 'other'
  }

  static async error(){
    throw new Error(this.error_message)
  }

}

const app = new Koa()
const router = new Router()

app.use(KoaApiHandle.error())
app.use(KoaApiHandle.tracking())

router.get('/ok', KoaApiHandle.response(MyHandler, 'ok'))
router.post('/other', KoaApiHandle.response(MyHandler, 'other'))
router.get('/error', KoaApiHandle.response(MyHandler.error.bind(MyError)))

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

app.use(KoaApiHandle.notFound())

app.listen()

Changes

v0.12.x -- Node 20+, pino for logger

https://github.com/mhio/node-koa-api-handle

0.12.1

1 year ago

0.12.0

1 year ago

0.12.0-3

1 year ago

0.12.0-4

1 year ago

0.12.0-1

3 years ago

0.12.0-2

3 years ago

0.11.0

5 years ago

0.10.10

5 years ago

0.10.9

5 years ago

0.10.5

5 years ago

0.10.7

5 years ago

0.10.8

5 years ago

0.10.4

5 years ago

0.10.1

5 years ago

0.10.2

5 years ago

0.10.3

5 years ago

0.10.0

5 years ago

0.10.0-3

5 years ago

0.10.0-2

5 years ago

0.10.0-1

5 years ago

0.9.0

6 years ago

0.9.0-1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.6.0-2

6 years ago

0.5.0

7 years ago

0.5.0-1

7 years ago

0.4.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago