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.

@FunctionalInterface public interface RequestInterceptor
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 Details

    • intercept

      ApiRequest intercept(ApiRequest request) throws ApiException
      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

      static RequestInterceptor logging(Consumer<String> logger)
      Creates a simple logging interceptor that logs request details.
      Parameters:
      logger - the logger function to use
      Returns:
      a request interceptor that logs requests
    • bearerAuth

      static RequestInterceptor bearerAuth(Supplier<String> tokenProvider)
      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

      static RequestInterceptor addHeaders(Map<String,String> headers)
      Creates a header interceptor that adds custom headers to all requests.
      Parameters:
      headers - the headers to add
      Returns:
      a request interceptor that adds headers