无法删除/使用快速REST

时间:2016-02-25 05:52:03

标签: node.js rest express

//api.js
var express = require('express')
var router = express.Router()
var bodyParser = require('body-parser')
var urls = require('../util/enums').urls;
var transaction = require('../controllers/transaction');

router.route(urls.API.TRANSACTIONS)
.get(transaction.getAll)
.post(transaction.addNewTransaction);

router.route(urls.API.TRANSACTION_INFO)
.get(transaction.findTransactionById);

router.get(urls.API.TRANSACTION_DEL, function(req,res){
    console.log('I am in delete');
    res.send('success');
});


router.get('/', function(req, res){
res.send("Now we are in API.js")
})


module.exports = router;

上面的代码到位后,我得到了成功的回复。

但是我在上面的代码中更改了删除方法,如下所示

router.delete(urls.API.TRANSACTION_DEL, function(req,res){
    console.log('I am in delete');
    res.send('success');
});

我收到此错误堆栈

SyntaxError: Unexpected token -
at parse (/Users/Rish/rishcreations/node_modules/body-parser/lib/types/json.js:83:15)
at /Users/Rish/rishcreations/node_modules/body-parser/lib/read.js:116:18
at invokeCallback (/Users/Rish/rishcreations/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
at done (/Users/Rish/rishcreations/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
at IncomingMessage.onEnd (/Users/Rish/rishcreations/node_modules/body-parser/node_modules/raw-body/index.js:308:7)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)

出现这种情况的想法是什么? 我正在使用邮递员提出请求,一切正常,除了这个删除。

是的,我正在使用永久保存并重新启动服务器。

0 个答案:

没有答案