1.0.6 • Published 5 years ago

nomi-router v1.0.6

Weekly downloads
9
License
ISC
Repository
github
Last release
5 years ago

Installation

$ npm install nomi-router --save

Node.js >= 8.0.0 required.

API

property

  • notation.RequestMapping
  • notation.Service

function

  • init

Usage

demo1: the usage of RequestMapping and Service in Controller.

const { RequestMapping, Service }  = require('nomi-router').notation;
 
@RequestMapping({
    path:"/order/{userId:num}",
    method:"post",
    middleware:['md1',"md1"]
})
class OrderController{
 
    @Service('service.orderService')
    serviceInst;
 
    @Service
    orderService;
 
    @RequestMapping({path:"/all/{type:string}",method:"get"})
    async index(req,res,paras,ctx) {
        res.body = this.serviceInst.loadAllOrders();
    }
 
    @RequestMapping("/user/{num:num}")
    async user(req,res,paras,ctx) {
        res.body = this.orderService.loadUserOrders();
    }
}
exports.OrderController = OrderController;

demo2: the usage of Service in Service.

const { Service }  = require('nomi-router').notation;
 
@Service('user.orderService')
class OrderService{
    async loadAllOrders() {
        console.log("loadAllOrders");
    }
 
    loadUserOrders(){
        console.log("loadUserOrders");
    }
}
exports.OrderService = OrderService;

demo3: the usage of init api

const r = require("nomi-router");
const router = await r.init({
        controllerPath:["/Controller/users","/Controller/orders"],
        servicePath:["/Service/users","/Service/orders"]
    });

/**
 * actObj: {
 *    action: {
 *        path: '/user/{userId: 123}/type/{type: string}',
 *        method: 'post',
 *        middleware: ['md1', 'md2'],
 *        action: [AsyncFunction: index],
 *        controller: OrderController { serviceInst: OrderService, orderService: OrderService },
 *        act: [Function: act]
 *    },
 *    paras: {
 *        userId: 123,
 *        type: 'hotel'
 *    }
 * }
*/
const actObj = router.match('/user/123/type/badorder','post');
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago