Nodejs api 404在访问url paremter时未发现错误

我正在做一个nodejs API,其中我从数据库中提取申请人的所有logging。 我的APIurl是这样的

var express = require('express'); var morgan = require('morgan'); var bodyParser = require('body-parser'); enter code here var ApplicantCtrl = require('./controllers/applicantController'); var app = express(); var port = process.env.Port || 8000; app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.get('api/applicant/:applicantId/getFullDetails', ApplicantCtrl.getApplicantAllData); app.listen(port, function() { console.log('Server is running on port : ' + port); }); 

和applicantController.js代码在这里

 var connection = require('./../config'); var helpers = require('../helpers/helper'); module.exports.getApplicantAllData = function(req , res) { var id = req.params.applicantId; console.log('in applicantallData'); helpers.getApplicantFullData(id) .then((data)=>{ if(data == null){ res.send({ meta : {status : 400, message : 'There is some error with query'} }); } else{ res.send({ meta : {status : 200, message : 'Success'}, data : data }); } }) .catch(function(err){ res.send({ meta : {status : 500, message : 'Internal Server Error'} }); }); } 

但是API的回应是这样的

 Cannot GET /api/applicant/23/getFullDetails 404 

有谁能告诉我这里有什么问题吗? 为什么api响应是404find的。

它看起来像是缺less快速应用程序中设置服务器路由的许多必要代码。 我认为这就是“在这里input代码”部分。

这里是一个关于build立一个非常基本的快递服务器的快速教程 。

对于你的例子中的URL,你将需要一个像这样的路由:

 router.get('/api/applicant/:id/getFullDetails', function(req, res) { // implementation here }); 

此外,不相干,但要更RESTFul,你可能想要稍微改变一下这样的URL: /api/applicants/:id/fullDetails