{title:'Extending RestClient', created:'8.2.0'}

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 {@link oajrc.RestRequest} and {@link oajrc.RestResponse} objects can also be extended and integrated by overriding the {@link oajrc.RestClient#createRequest(URI, String, boolean)} and {@link oajrc.RestClient#createResponse(RestRequest, HttpResponse, Parser)} methods.