Anders Lassen
Anders Lassen

Reputation: 79

Zuul: How to get path variables from request

Using Zuul, how do I extract the path variables (customerId and agreementId) given the following URL:

customers/{customerId}/agreements/{agreementId}

Can I somehow get the reference names for the path variables using Zuul or Eureka or do I need to use RegEx or something similar?

Upvotes: 1

Views: 1706

Answers (3)

Thomas Huang
Thomas Huang

Reputation: 1

I also have such a demand recently, I am studying how to solve this problem, you can refer to the AntPathMatcher class in Spring Core, maybe it will help you

Upvotes: 0

Abhijay
Abhijay

Reputation: 328

You can add a filter which will be used before your request actually goes to the controller.

You can extract path variables from HttpServletRequest like this:

Map<String, String> pathVariables = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

Upvotes: 0

Mayank J
Mayank J

Reputation: 71

RegEx is definitely one of the option to explore

Upvotes: 1

Related Questions