想问下express支不支持put/delete等请求类型
我最近在做一个项目,用到了express,上面跑的是管理端的代码,有一个view是express渲染的,另外还要做一套api给前端用,想搞成rest风格的,就想问下express有没有app.delete之类的东西,如果不支持应该怎么搞。完全是个小白,大神不要见笑
7 回复
var express = require('express');
var router = express.Router();
var $ = require('../controllers/users_controller');
// -- custom
/**
* Auto generate RESTful url routes.
*
* URL routes:
*
* GET /users[/] => user.list()
* GET /users/new => user.new()
* GET /users/:id => user.show()
* GET /users/:id/edit => user.edit()
* POST /users[/] => user.create()
* PATCH /users/:id => user.update()
* DELETE /users/:id => user.destroy()
*
*/
router.get('/new', $.new);
router.get('/:id/edit', $.edit);
router.route('/')
.get($.list)
.post($.create);
router.route('/:id')
.patch($.update)
.get($.show)
.delete($.destroy);
module.exports = router;
put和patch是有争议的,推荐patch
@i5ting 狼叔厉害
@i5ting 你链接的项目有地址吗
@i5ting 顶狼叔