Package io.mochaapi.client
Interface RequestInterceptor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Interface for intercepting and modifying HTTP requests before they are sent.
Allows developers to add logging, authentication, or modify request details.
Example usage:
ApiClient client = new ApiClient.Builder()
.addRequestInterceptor(request -> {
System.out.println("Sending request to: " + request.getUrl());
return request;
})
.build();
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic RequestInterceptoraddHeaders(Map<String, String> headers) Creates a header interceptor that adds custom headers to all requests.static RequestInterceptorbearerAuth(Supplier<String> tokenProvider) Creates an authentication interceptor that adds a Bearer token to requests.intercept(ApiRequest request) Intercepts and optionally modifies a request before it is sent.static RequestInterceptorCreates a simple logging interceptor that logs request details.
-
Method Details
-
intercept
Intercepts and optionally modifies a request before it is sent.- Parameters:
request- the original request- Returns:
- the (possibly modified) request to send
- Throws:
ApiException- if the interceptor needs to abort the request
-
logging
Creates a simple logging interceptor that logs request details.- Parameters:
logger- the logger function to use- Returns:
- a request interceptor that logs requests
-
bearerAuth
Creates an authentication interceptor that adds a Bearer token to requests.- Parameters:
tokenProvider- function that provides the current token- Returns:
- a request interceptor that adds authorization headers
-
addHeaders
Creates a header interceptor that adds custom headers to all requests.- Parameters:
headers- the headers to add- Returns:
- a request interceptor that adds headers
-