I'm constructing a restful service which needs to accept any number of parameters instead of the one from the sample below.
Assuming the following service routine
@RequestMapping("/start/id/{id}", RequestMethod.GET)
public void startService(@PathVariable String id) {...}
there's a client implementation based on RestTemplate
restTemplate.getForObject("/start/id/{id}", null, id);
Question: But given that it might be thousands of ids
, what restful approaches do I have to sending all parameters in one request using RestTemplate
? I've seen the suggestions
- Add request body to GET request - Doesn't seem possible with
RestTemplate
? - Use a separator in id, (e.g.,
id1|id2|....|idn
) - Seems like a hack - PUT the parameters first, then issue a GET to reference the ids - Double requests, seems non-intuitive
- Adding multiple URL parameters (
?id=foo&id=bar&.....&id=foobar
)
I know similar questions (calling-a-restful-service-with-many-parameters, how-to-create-rest-urls-without-verbs, can-you-build-a-truly-restful-service-that-takes-many-parameters) has been asked before but I found it hard to spot a satisfactory answer, or at least an answer based on RestTemplate
.