Yet another (but missing for us) simple RESTful client Java library, that support both JSON and XML REST API, based on the great Apache HttpClient.
We begun writing this library when coding the first integration tests for ClouDesire backend.
Nowadays there are a lot of alternatives, like OkHttp, Unirest, but we are still in love with this.
- Internally use Apache HttpClient
- Support for GET, POST, PUT, PATCH, DELETE methods
- Standard java.net.URL to supply request URL and GET parameters
- De/Serilization of Request/Response bodies via supplied .class (via Jackson and JAXB)
- Errors always mapped to a RestException hierarchy
- Ability to define a custom ExceptionTranslator to map your Exceptions or custom error handling
<dependency>
<groupId>com.cloudesire</groupId>
<artifactId>tisana4j</artifactId>
<version>0.0.24</version>
</dependency>
More examples in the integration tests package.
public class Test {
private static class NetworkAddress {
private String ip;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
}
public static void main(String[] args) throws Exception {
// default Client: no credentials
RestClient client = new RestClient();
NetworkAddress testClass = client.get(new URL("http://ip.jsontest.com/"), NetworkAddress.class);
System.out.println("YOUR IP:" + testClass.getIp());
}
}