1
@RequestMapping(value = "/{ids}", method=RequestMethod.GET)
public String getMethod(@PathVariable List<String> ids){

}

I would like something similar, but I need the request to map to something like: localhost:8080/id1/id2/id3/.../idn

I don’t know the number of path variables (ids) and neither their names.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Andreea
  • 11
  • 3

2 Answers2

0

When you are using a path it essentially adds to the uri . The uri has length limitations. Related post : Maximum length of HTTP GET request

So it is not advisable to add multiple number of parameters to the uri as path variable, when the number is not restricted.

You could use query params like :

@RequestMapping(value = "/{ids}", method=RequestMethod.GET)
public String getMethod(@RequestParam("myparam") List<String> ids) 
{ 
}

Instead what you could have is convert it to a post request and have a request body with the list of data as an object.

@PostMapping("/")
public ResponseEntity postController(
  @RequestBody CustomPojo data) {
 
    exampleService.fakeAuthenticate(data);
    return ResponseEntity.ok(HttpStatus.OK);
}

class CustomPoJo {
  List<String> ids;
//getter setter etc
}

and the json could look like :

{"custompojo":["id1","id2"]}
Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39
0

It cannot be done since the request will look for endpoint having matching URL and matching method.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197