Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sombriks/koa-api-builder
Helper to build koa-router apis easily
https://github.com/sombriks/koa-api-builder
api-builder koa koa-router node
Last synced: 28 days ago
JSON representation
Helper to build koa-router apis easily
- Host: GitHub
- URL: https://github.com/sombriks/koa-api-builder
- Owner: sombriks
- License: mit
- Created: 2023-08-26T14:46:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-29T17:11:55.000Z (about 1 year ago)
- Last Synced: 2024-10-16T19:12:00.584Z (3 months ago)
- Topics: api-builder, koa, koa-router, node
- Language: JavaScript
- Homepage:
- Size: 183 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# [Koa-api-builder](https://github.com/sombriks/koa-api-builder)
![tests and coverage](https://github.com/sombriks/koa-api-builder/actions/workflows/node.js.yml/badge.svg)
[![npm version](https://img.shields.io/npm/v/koa-api-builder?style=plastic)](https://www.npmjs.com/package/koa-api-builder)
[![license](https://img.shields.io/github/license/sombriks/koa-api-builder.svg)](LICENSE)Helper to build [koa-router](https://github.com/koajs/router) apis easily
## Dependencies
- node 14 or higher
- koa-router
- koa## Sample usage
```javascript
import ApiBuilder from "koa-api-builder";const group = new ApiBuilder().path((group) => {
group.post('/login', loginRequest)
.post('/signup', signupRequest)
.path('/user/:userId/accounts', ifAuthenticated, (group) => {
group.get(listAccountsRequest)
.post(ifAllowed, insertAccountRequest)
.path('/:accountId', (group) => {
group.get(findAccountRequest);
group.put(updateAccountRequest);
group.del(ifAllowed, delAccountRequest);
group.get('/transactions', listTransactionsRequest);
});
});
});// then we build our api definition into a regular koa-router
const router = group.build();
```## Similar libraries
See router section on [koa wiki](https://github.com/koajs/koa/wiki#routing-and-mounting)
## Inspiration
This api builder is heavily copied from [Javalin's group handler](https://javalin.io/documentation#handler-groups)
## Roadmap
- [X] Initial implementation
- [X] Test and coverage
- [X] Publish npm package
- [X] Add linting tool
- [X] Publish every new tag
- [ ] Publish coverage results
- [ ] ~~Add special `render` pseudo-verb for template engines~~
- [ ] Add Server Sent Events configuration support
- [ ] Add WebSockets configuration supportSee the [changelog](CHANGELOG.md) for more details