nomi-router
This is the router moudle of nomi node framework
Last updated 9 months ago by weoguo.kong.nomi .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nomi-router 
SYNC missed versions from official npm registry.

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');

Current Tags

  • 1.0.6                                ...           latest (9 months ago)

6 Versions

  • 1.0.6                                ...           9 months ago
  • 1.0.5                                ...           10 months ago
  • 1.0.4                                ...           10 months ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
Downloads
Today 0
This Week 1
This Month 5
Last Day 1
Last Week 2
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |