@4lch4/koa-oto 中文文档教程

发布于 3年前 浏览 22 更新于 3年前

NPM Standard-JsCodecovCodacy Badge

CI/CD Pipelinenpm (tag)GitHub tag (latest SemVer)

@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:

Code-Coverage-Icicle

Code-Coverage-Tree

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.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文