I am trying to build a REST API with express router, which contains of nested sub routes. I have mounted these sub routes in my index.js
file.
I have defined it as follows:
// Mounted routes
app.use('/api/v1/Project', new ProjectRouter().routes);
app.use('/api/v1/Project/:projectId/Context', new ContextRouter().routes);
app.use('/api/v1/Project/:projectId/Context/:contextId/Question', new QuestionRouter().routes);
app.use('/api/v1/Project/:projectId/Context/:contextId/Question/:questionId/Answer', new AnswerRouter().routes);
I want to arrange my routes revolved around the functionality and being more complaint towards REST standards.
In the above case the route prefix
/api/v1/Project/
is being repeated over and over again.Is there some best practice to minimize the redundant routes by prefixing?
In the case the route prefix /api/v1/Project/
is being repeated over and over again.
Is there some best practice to minimize the redundant routes by prefixing?