@axiosleo/koapp
TypeScript icon, indicating that this package has built-in type declarations

1.0.23 • Public • Published

@axiosleo/koapp

NPM version npm download CI Build Status License FOSSA Status

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.

FOSSA Status

Readme

Keywords

none

Package Sidebar

Install

npm i @axiosleo/koapp

Weekly Downloads

14

Version

1.0.23

License

MIT

Unpacked Size

73.3 kB

Total Files

41

Last publish

Collaborators

  • axiosleo