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
RestTemplate?id1|id2|....|idn) - Seems like a hack?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.
I don't think any part of RESTful design states that your url structure should be able to resolve entire collections. Your first (request parameter) and third (url parameter) suggestions are likely the best.
I would recommend the first. I'm sure its allowed in resttemplate. Looking at the documentation you provided, just implement one of the post methods. Each of them takes the request as a parameter. Inside there, I'm sure there is some kind of implementation of a getRequestParameters() method you can use to parse json/xml from the request body containing your ids.
Or, even better, how are all of these id's related? Do they all have a common parent resource? If so, then you could (and probably should) do something like...
/commonparent/{parentId}
And then inside your request handler, query for all of the ids, and procede like normal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With