Reputation: 21
I have two 2 routes as follows:
1) /company/:companyId/brand/:brandId/order/:orderId
2) /company/:companyId/brand/:brandId/order/getOrders?count=10
When I try calling the second route, the first route gets invoked. Also, if first route is not present then second one gets invoked successfully. I am not sure how is the first route getting called even when it doesn't have the 'getOrders' path URI. How is it even selected while matching the path URI ?
Upvotes: 1
Views: 556
Reputation: 11132
The order in which you define the routes is important, put the most specific route first, in your case the 2nd one.
router.get("/company/:companyId/brand/:brandId/order/getOrders?count=10").handler(ctx -> ...)
router.get("/company/:companyId/brand/:brandId/order/:orderId").handler(ctx -> ...)
Other option, if one of your "upper" contextHandlers finds out it's not responsible for dealing with the request (such as your 1st is not responsible for responding to requests for the 2nd), you could just call next()
on the context and return
router.get("/company/:companyId/brand/:brandId/order/:orderId")
.handler(ctx -> {
if(shouldHandleRequest(ctx)) {
//respond
ctx...end();
} else {
ctx.next(); //skip to next handler
});
router.get("/company/:companyId/brand/:brandId/order/getOrders?count=10")
.handler(ctx -> ...)
Upvotes: 2