Skip to content

About Design for quickly developing OpenAPI applications using Node.js

License

Notifications You must be signed in to change notification settings

AxiosLeo/node-koapp

Repository files navigation

@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

About

About Design for quickly developing OpenAPI applications using Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published