1

URL: /api/v1/user ? type=abc & company=xyz

In an API call, we can extract the query param by using @QueryParam annotation. But, we have to define the query parameter key for mapping.

@QueryParam("type") String type
@QueryParam("company") String company

In case, we have dynamic parameters coming in like page=2 & limit=10 & skip=20 & type=abc ... and we are making another call to a different service using a rest client. Here, we have to pass all the query parameters whatever are received in the request to that service.

How can we read and add these query params to the Request?

1 Answer 1

2

You could try to use a Map and define the queryparams in that like so.

@RequestParam Map<String,String> params

Then you can find the required variables in the params map as such:

params.get("type");

Then when you make your request, you can create some logic for if the map contains the certain param, then use it :)


When you define @RequestParam without a specific parameter to target, it will extract all params and inject into the map.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.