-
Notifications
You must be signed in to change notification settings - Fork 28
java_client
Entry points are commonly defined through a resource retrieval or creation request. Restfulie allows you to use both type of entry points through its API.
Most systems will create a request retrieval entry point, which can be accessed as:
Response response = Restfulie.at('http://localhost:3000/cities/5').get(); City city = response.getResource();
After that, the xml tree can be accessed and links followed. A typical city hypermedia file would be:
<city> <name>Sao Paulo</name> <population> <size>18000000</size> <growth>10</growth> </population> <link rel="next_largest" href="http://localhost:3000/cities/18" /> </city>
The information can be retrieved through the usual method invocations:
System.out.println(city.getName()); System.out.println(city.getPopulation().getSize()); System.out.println(city.getPopulation().getGrowth());
And links can be followed as:
Link link = resource(city).getLink("next_largest");
Note that the client application knows what the rel attribute next_largest means, but does not know what it's value stands for (Rio de Janeiro).
In this case, you can access the http response through response, i.e.:
Response response = Restfulie.at('http://localhost:3000/cities/5').get() System.out.println.("Response code" + response.getCode());
The return of such web_response method is an object of Restfulie::Client::HTTPResponse and allows you to access methods to check whether the request was successful or any other group of response codes:
Response response = Restfulie.at('http://localhost:3000/cities/5').get(); puts "Response code #{city.web_response.is_successful?}" puts "Response code #{city.web_response.is_client_error?}" do we have it in java?
If your server defines an entry point related to a resource creation, you can use the create method as:
Response response = Restfulie.at('http://localhost:3000/cities').post(city); City city = response.getResource();
Note that city seems to be the result of following a 201 response to its given Location header.