Extending RestClient
The RestClient API has been designed to allow for the ability to be easily extended.
The following example that overrides the primary run method shows how this can be done.
Example
public class MyRestClient extends RestClient {
// Must provide this constructor!
public MyRestClient(ContextProperties ps) {
super(ps);
}
@Override
public HttpResponse run(HttpHost target, HttpRequest request, HttpContext context) throws IOException {
// Perform special handling of requests.
}
}
// Instantiate your client.
MyRestClient client = RestClient.create().json().build(MyRestClient.class);
The RestRequest and RestResponse objects can also be extended and integrated by overriding the createRequest(URI, String, boolean) and createResponse(RestRequest, HttpResponse, Parser) methods.