Skip to main content

Interceptors

The RestCallInterceptor API provides a quick way of intercepting and manipulating requests and responses beyond the existing HttpRequestInterceptor and HttpResponseInterceptor APIs.

RestClient.Builderinterceptors(Object...)RestRequestinterceptors(RestCallInterceptor...)RestCallInterceptoronInit(RestRequest)onConnect(RestRequest,RestResponse)onClose(RestRequest,RestResponse)
Example
// Create a client with a customized interceptor.
RestClient client = RestClient
.create()
.interceptors(
new RestCallInterceptor() {

@Override
public void onInit(RestRequest req) throws Exception {
// Intercept immediately after RestRequest object is created and all headers/query/form-data has been
// set on the request from the client.
}

@Override
public void onConnect(RestRequest req, RestResponse res) throws Exception {
// Intercept immediately after an HTTP response has been received.
}

@Override
public void onClose(RestRequest req, RestResponse res) throws Exception {
// Intercept when the response body is consumed.
}
}
)
.build();