public interface RequestInterceptor
An interceptor may handle a request in any way it sees fit. It may update a request before it's sent, or it may choose to return a custom response. If an interceptor returns a null response, then the request will continue to be sent to the API along with any changes that the interceptor may have made to it.
public BoxAPIResponse onRequest(BoxAPIRequest request) { request.addHeader("My-Header", "My-Value"); // Returning null means the request will be sent along with our new header. return null; }
However, if a response is returned, then the request won't be sent and the interceptor's response will take the place of the normal response.
public BoxAPIResponse onRequest(BoxAPIRequest request) { // Returning our own response means the request won't be sent at all. return new BoxAPIResponse(); }
A RequestInterceptor can be very useful for testing purposes. Requests to the Box API can be intercepted and fake responses can be returned, allowing you to effectively test your code without needing to actually communicate with the Box API.
Modifier and Type | Method and Description |
---|---|
BoxAPIResponse |
onRequest(BoxAPIRequest request)
Invoked when a request is about to be sent to the API.
|
BoxAPIResponse onRequest(BoxAPIRequest request)
request
- the request that is about to be sent.