在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:alexmingoia/koa-resource-router开源软件地址:https://github.com/alexmingoia/koa-resource-router开源编程语言:JavaScript 100.0%开源软件介绍:koa-resource-routerRESTful resource routing for koa.
InstallationInstall using npm: npm install koa-resource-router APInew Resource(path, actions, options)var Resource = require('koa-resource-router');
var app = require('koa')();
var users = new Resource('users', {
// GET /users
index: function *(next) {
},
// GET /users/new
new: function *(next) {
},
// POST /users
create: function *(next) {
},
// GET /users/:id
show: function *(next) {
},
// GET /users/:id/edit
edit: function *(next) {
},
// PUT /users/:id
update: function *(next) {
},
// DELETE /users/:id
destroy: function *(next) {
}
});
app.use(users.middleware()); Action mappingActions are then mapped accordingly: GET /users -> index
GET /users/new -> new
POST /users -> create
GET /users/:user -> show
GET /users/:user/edit -> edit
PUT /users/:user -> update
DELETE /users/:user -> destroy Overriding action mappingvar users = new Resource('users', actions, {
methods: {
update: 'PATCH'
}
}); Top-level resourceOmit the resource name to specify a top-level resource: var root = new Resource(require('./frontpage')); Top-level controller actions are mapped as follows: GET / -> index
GET /new -> new
POST / -> create
GET /:id -> show
GET /:id/edit -> edit
PUT /:id -> update
DELETE /:id -> destroy NestingResources can be nested using var forums = new Resource('forums', require('./forum'));
var threads = new Resource('threads', require('./threads'));
forums.add(threads); Multiple middlewareRun middleware before resource actions by passing middleware functions before your actions: var users = new Resource('users', authorize, actions); Run middleware for specific actions by passing an array: var users = new Resource('users', {
show: [authorize, function *(next) {
// ...
}]
}); MIT Licensed |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论