https://github.com/4lch4/koa-oto
A library for responding to requests within the Koa framework.
https://github.com/4lch4/koa-oto
Last synced: 3 months ago
JSON representation
A library for responding to requests within the Koa framework.
- Host: GitHub
- URL: https://github.com/4lch4/koa-oto
- Owner: 4lch4
- Created: 2021-09-26T22:31:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T01:06:07.000Z (about 1 year ago)
- Last Synced: 2025-02-26T17:52:55.826Z (3 months ago)
- Language: TypeScript
- Size: 256 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
> [!IMPORTANT]
> This repo has been archived as I've switched to [Elysia](https://elysiajs.com) for my preferred API framework.
>
> Feel free to fork and modify this repo to suit your needs. [](https://standardjs.com/) [](https://codecov.io/gh/4lch4/koa-oto) [](https://www.codacy.com/gh/4lch4/koa-oto/dashboard?utm_source=github.com&utm_medium=referral&utm_content=4lch4/koa-oto&utm_campaign=Badge_Grade)
[](https://github.com/4lch4/koa-oto/actions/workflows/CI.yml) [](https://npmjs.org/package/4lch4/koa-oto) [](https://github.com/4lch4/koa-oto/packages/)
# @4lch4/koa-oto
This library is a responder library for handling responses within the [Koa][0] 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 😅_][1]
## Example Usage
It isn't much, but this is the most basic way to use the library within your API:
```typescript
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.[0]: https://github.com/koajs/koa
[1]: https://translate.google.com/?sl=en&tl=ja&text=respond%0A&op=translate