@4lch4/koa-oto 中文文档教程
@4lch4/koa-oto
This library is a responder library for handling responses within the Koa framework.
The Name
The name "Koa-Ōtō" is a combination of Koa (duh), and the Japanese Romaji version of 応答 (Ōtō) which means "Respond".
NOTE: According to Google Translate at least ????
Example Usage
It isn't much, but this is the most basic way to use the library within your API:
import { ClientErrors, Successful } from '@4lch4/koa-oto'
import Router from '@koa/router'
import Koa from 'koa'
const app = new Koa()
const router = new Router()
router.get('/', async ctx => Successful.ok(ctx, 'Hello World'))
router.get('/error', ctx => ClientErrors.badRequest(ctx, 'Bad Request'))
app.use(router.routes())
app.use(router.allowedMethods())
app.listen(3000, () => {
console.log('Server is running on port 3000')
})
Testing and Coverage
I went a really weird route for testing this library, but in the end I've achieved a solid coverage percentage in CodeCov. The following images are an icicle and grid representation of the current test coverage:
Icicle: The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid: Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.