Imakesense
Imakesense

Reputation: 17

Rest API with mix of Path Param and RequestParam

I have been asked to build a Rest endpoint that is a mix of path param and request param, looks like -

/user/{user}?refresh={refresh}

The request param should be optional.

I have tried String getUser(@PathVariable String user, @RequestParam Map<String, String> params); but it makes the RequestParam mandatory (as it shows in Swagger UI).

How can I make it optional ?

Upvotes: 0

Views: 1946

Answers (1)

cassiomolin
cassiomolin

Reputation: 130857

Set required to false in the @RequestParam annotation, as follows:

@GetMapping("/user/{user}?refresh={refresh}")
String getUser(@PathVariable String user, @RequestParam(required = false) String refresh) {
    ...
}

Upvotes: 2

Related Questions