我找到了Difference between put and patch。我在閱讀之後明白了差異。它仍然朦朧。爲什麼angular-fullstack使用put和patch請求來表達?
我的問題是: 爲什麼約曼發電機:angular fullstack使用
router.put('/:id', controller.update);
AND
router.patch('/:id', controller.update);
在有index.js他們server.collections的文件?
兩者的目的是什麼?此外,我將如何使用一個和另一個?
'use strict';
var express = require('express');
var controller = require('./thing.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
module.exports = router;
服務器控制器
// Updates an existing thing in the DB.
exports.update = function(req, res) {
if(req.body._id) { delete req.body._id; }
Thing.findById(req.params.id, function (err, thing) {
if (err) { return handleError(res, err); }
if(!thing) { return res.send(404); }
var updated = _.merge(thing, req.body);
updated.save(function (err) {
if (err) { return handleError(res, err); }
return res.json(200, thing);
});
});
};
我很好奇補丁如何知道如何部分修改資源?前端的PUT和PATCH就像標誌,我假設。如果我猜測,這是因爲服務器技術知道如何處理這些標誌並採取相應的行動。由於我一起使用express + mongo,所以這些技術知道如何處理PATCH標誌。那是對的嗎? –