fghjklwag
fghjklwag

Reputation: 29

Multiple path variables in one url

I am trying to construct a URL that can take in multiple ids at once so I am able to return two people at once, but I am getting a number format exception

String url = "http://test.com/Services/people/{id}/Identifier"
Map<String, String> params = new HashMap<String, String>();
params.put("id", {"1234","5678"});
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
                                    .queryParam("DOB", "myDOB");
String uriBuilder = builder.build().encode().toUriString();
restTemplate.exchange(uriBuilder , HttpMethod.PUT, requestEntity,
                class_p, params);

This is getting a number format exception from passing in multiple ids, is there a way to do that in a different format?

Upvotes: 0

Views: 1893

Answers (1)

Andreas
Andreas

Reputation: 159260

GET /Services/people/42 is a request for "people" resource with id 42.

A request for multiple people by some criteria is not a resource request, but a query, so should use query parameters.
E.g. GET /Services/people/find?id=13&id=29
or maybe POST /Services/people/find with payload {"id": [1234, 5678]} (Content-Type: application/json).

What you're trying to do is wrong, for a RESTful service.

Upvotes: 2

Related Questions