@5no/router 中文文档教程
Router
具有架构
Install
@5no/router 的 Express 路由器需要 Node 版本 8 或更高版本。
npm install --save @5no/router
Examples
import Router from '@5no/router'
const schema = {
id: {
type: Number,
defaultValue: null,
required: true,
},
}
app.use(Router({
path: '/test',
actions: [
{
path: '/:id',
method: 'GET',
schema: schema,
handler: (req, res) => res.action.success(req.action.data.id),
},
],
}))
/**
*
* url: /test
* method: OPTIONS
* response:
*
{
"status": 200,
"success": true,
"message": [
{
"path": "/test/:id",
"method": "GET",
"schema": {
"id": {
"type": "number",
"required": true,
"defaultValue": null
}
}
}
]
}
*
*
*
* /
/**
*
* url: /test/123
* method: GET
* response:
*
{
"status": 200,
"success": true,
"message": 123
}
*
*
*
* /
License
MIT 许可,版权所有 (c) 2020 Aleksandr Sokol
Router
Express router with schema
Install
@5no/router requires Node version 8 or above.
npm install --save @5no/router
Examples
import Router from '@5no/router'
const schema = {
id: {
type: Number,
defaultValue: null,
required: true,
},
}
app.use(Router({
path: '/test',
actions: [
{
path: '/:id',
method: 'GET',
schema: schema,
handler: (req, res) => res.action.success(req.action.data.id),
},
],
}))
/**
*
* url: /test
* method: OPTIONS
* response:
*
{
"status": 200,
"success": true,
"message": [
{
"path": "/test/:id",
"method": "GET",
"schema": {
"id": {
"type": "number",
"required": true,
"defaultValue": null
}
}
}
]
}
*
*
*
* /
/**
*
* url: /test/123
* method: GET
* response:
*
{
"status": 200,
"success": true,
"message": 123
}
*
*
*
* /
License
MIT Licensed, Copyright (c) 2020 Aleksandr Sokol