https://github.com/axiosleo/node-koapp
About Design for quickly developing OpenAPI applications using Node.js
https://github.com/axiosleo/node-koapp
Last synced: 2 months ago
JSON representation
About Design for quickly developing OpenAPI applications using Node.js
- Host: GitHub
- URL: https://github.com/axiosleo/node-koapp
- Owner: AxiosLeo
- License: mit
- Created: 2022-07-25T06:53:28.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T02:13:40.000Z (4 months ago)
- Last Synced: 2025-04-05T15:11:17.868Z (3 months ago)
- Language: JavaScript
- Size: 172 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @axiosleo/koapp
[](https://npmjs.org/package/@axiosleo/koapp)
[](https://npmjs.org/package/@axiosleo/koapp)
[](https://github.com/AxiosLeo/node-koapp/actions/workflows/ci.yml)
[](https://codecov.io/gh/AxiosLeo/node-koapp)
[](LICENSE)
[](https://app.fossa.com/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-koapp/refs/branch/master)> Design for quickly developing Web applications using Node.js
>
> Based on [koa](https://koajs.com/)```bash
npm install @axiosleo/koapp
```## Initialization
```bash
npx @axiosleo/koapp init -d# show help info
# npx @axiosleo/koapp init -h
```## Quick Start
```javascript
const { KoaApplication, Router, success } = require("@axiosleo/koapp");const handle = async (ctx) => {
success({
message: "Hello World!",
});
};const router = new Router("/test", {
method: "any",
handlers: [handle],
});const app = new KoaApplication({
port: 8088,
listen_host: "localhost", // 0.0.0.0 for public access
routers: [router],
});
app.start();// open http://localhost:8088/test
```## More Examples
- Validation
> see [validatorjs](https://github.com/mikeerickson/validatorjs) for more rule examples
>
> see `Router` examples for more usage: [tests/bootstrap.js](tests/bootstrap.js)```javascript
const { Router } = require("@axiosleo/koapp");const router = new Router("/test", {
method: "any",
validator: {
// url params, like `/test/{:id}`, the 'id' is required and must be an integer
params: {
id: "required|integer",
},
query: {
name: "required|string",
},
body: {
age: "required|integer",
}
}
handlers: [],
});
```- SSE
```javascript
const { _foreach, _sleep } = require("@axiosleo/cli-tool/src/helper/cmd");const test = async (context) => {
await _foreach(["0", "1", "2", "3"], async (item, index) => {
context.koa.sse.send({ data: { item, index } });
await _sleep(1000);
});
context.koa.sse.end();
};const { KoaSSEMiddleware } = require("@axiosleo/koapp");
root.any("/sse", async (context) => {
const func = KoaSSEMiddleware();
await func(context.koa, async () => {});
context.koa.sse.send({ data: "hello, world!" });
process.nextTick(test, context);
});
```## License
This project is open-sourced software licensed under [MIT](LICENSE).
[](https://app.fossa.com/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-koapp/refs/branch/master/)