I am using following api which responds nothing http://localhost:6150/api/v1/simpleSurveyData/abc/:projectId/:startDate/:endDate/:visitMonth
but, when i remove any of the four params or give less than four params. And adjust api route in node js accordingly server starts to response.
What i found is increasing params to four, my Node JS code does not come into the api route but although server does not give error but request just sending.
router.get("api/v1/simpleSurveyData/abc/:projectId/:startDate/:endDate/:visitMonth",
async (req, res, next) => {
console.log("first")
try {
console.log("first")
res.status(200).send("response");
} catch (error) {
next(error);
console.log(error);
}
}
);
The problem is because you extract the data from url path NOT a query parameter. Please use query parameter. Example code below.
"api/v1/simpleSurveyData/abc/:projectId/:startDate/:endDate/:visitMonth" should be "api/v1/simpleSurveyData/abc?projectId=<projectId>&startDate=<startDate>&endDate=<endDate>&visitMonth=<visitMonth>"
Example express controller
export async function upvoteQuestion(req: Request, res: Response, next: NextFunction): Promise<void> {
try {
const questionId: string = req.params.question_id
await db<Question>('question').where('id', questionId).increment('upvote', 1)
res.status(200).json(<GeneralResponse>{
status: responseStatus.success,
message: 'Successfully vote up question'
})
} catch (error: unknown) {
next(error)
}
}
I extract the information of question id in url parameter by using req.params.question_id.
You can Google for more information.