@axiosleo/koapp
v1.0.23
Published
[![NPM version](https://img.shields.io/npm/v/@axiosleo/koapp.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/koapp) [![npm download](https://img.shields.io/npm/dm/@axiosleo/koapp.svg?style=flat-square)](https://npmjs.org/package/@axiosleo/koap
Downloads
321
Readme
@axiosleo/koapp
Design for quickly developing Web applications using Node.js
Based on koa
npm install @axiosleo/koapp
Initialization
npx @axiosleo/koapp init <app-name> -d <optional-dir>
# show help info
# npx @axiosleo/koapp init -h
Quick Start
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 for more rule examples
see
Router
examples for more usage: tests/bootstrap.js
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: [],
});
License
This project is open-sourced software licensed under MIT.