Skip to content
/ koa-oto Public

A library for responding to requests within the Koa framework.

Notifications You must be signed in to change notification settings

4lch4/koa-oto

Repository files navigation

Important

This repo has been archived as I've switched to Elysia for my preferred API framework.

Feel free to fork and modify this repo to suit your needs.

NPM Standard-Js Codecov Codacy Badge

CI/CD Pipeline npm (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.

About

A library for responding to requests within the Koa framework.

Resources

Stars

Watchers

Forks

Packages