membersound
membersound

Reputation: 86727

How to make dynamic RESTful service calls?

I want to make a restful webservice call to http://www.cleartrip.com/places/hotels/info/41748

How can I form dynamic properties in the request string? The following is what I tried and does not work:

Client client = ClientBuilder.newClient();
client.property("hotelnr", 41748);

//works not (HTTP 404 Not Found):
client.target("http://www.cleartrip.com/places/hotels/info/{hotelnr}").request(MediaType.APPLICATION_XML).get();

//works:
client.target("http://www.cleartrip.com/places/hotels/info/41748").request(MediaType.APPLICATION_XML).get();

Upvotes: 0

Views: 522

Answers (1)

emgsilva
emgsilva

Reputation: 3065

Take a look in: http://docs.oracle.com/javaee/7/tutorial/doc/jaxrs-client001.htm#sthref1397

You can do as follows:

WebTarget myResource = client.target("http://example.com/webapi/read")
  .path("{userName}");
Response response = myResource.queryParam("userName", "janedoe")
  .request(...)
  .get();

Upvotes: 4

Related Questions