Class ApacheWpRestClientBuilder

java.lang.Object
io.github.evisentin.wordpress.client.adapter.apache.ApacheWpRestClientBuilder

public final class ApacheWpRestClientBuilder extends Object
Builder for creating ApacheWpRestClient instances.

The builder supports configuration of SSL/TLS settings, request timeouts, and custom Apache HttpClient request and response interceptors. Authentication is mandatory and must be provided through one of the available factory methods.

Example using HTTP Basic Authentication:


 ApacheWpRestClient client =
     ApacheWpRestClientBuilder
         .basicAuthentication(
             "https://my-wordpress-site.com", // this must be the ROOT url, the client will find the API-URL via discovery
             "user",
             "password"
         )
         .withTimeoutConfiguration(timeoutConfiguration)
         .build();
 

Example using JWT Authentication:


 ApacheWpRestClient client =
     ApacheWpRestClientBuilder
         .jwtAuthentication(
             "https://my-wordpress-site.com", // this must be the ROOT url, the client will find the API-URL via discovery
             "user",
             "password",
             "/jwt-auth/v1/token" // ths must be relative to the API-URL
         )
         .build();
 
  • Method Details

    • build

      public ApacheWpRestClient build()
      Builds a configured ApacheWpRestClient.
      Returns:
      A new REST client instance.
    • withInterceptor

      public ApacheWpRestClientBuilder withInterceptor(@NonNull @NonNull org.apache.hc.core5.http.HttpRequestInterceptor interceptor)
      Adds a custom Apache HttpClient request interceptor.

      Request interceptors are executed in the order they are added before a request is sent.

      Parameters:
      interceptor - Request interceptor to add.
      Returns:
      This builder instance.
    • withInterceptor

      public ApacheWpRestClientBuilder withInterceptor(@NonNull @NonNull org.apache.hc.core5.http.HttpResponseInterceptor interceptor)
      Adds a custom Apache HttpClient response interceptor.

      Response interceptors are executed in the order they are added after a response is received.

      Parameters:
      interceptor - Response interceptor to add.
      Returns:
      This builder instance.
    • withSslConfiguration

      public ApacheWpRestClientBuilder withSslConfiguration(@NonNull @NonNull SslConfiguration sslConfiguration)
      Configures SSL/TLS settings for the client.
      Parameters:
      sslConfiguration - SSL configuration to use.
      Returns:
      This builder instance.
    • withTimeoutConfiguration

      public ApacheWpRestClientBuilder withTimeoutConfiguration(@NonNull @NonNull TimeoutConfiguration timeoutConfiguration)
      Configures request timeout settings for the client.
      Parameters:
      timeoutConfiguration - Timeout configuration to use.
      Returns:
      This builder instance.
    • basicAuthentication

      public static ApacheWpRestClientBuilder basicAuthentication(@NonNull @NonNull String baseUrl, @NonNull @NonNull String username, @NonNull @NonNull String password)
      Creates a builder configured for HTTP Basic Authentication.
      Parameters:
      baseUrl - Base URL of the WordPress instance.
      username - Username used for authentication.
      password - Password used for authentication.
      Returns:
      A new builder instance.
    • jwtAuthentication

      public static ApacheWpRestClientBuilder jwtAuthentication(@NonNull @NonNull String baseUrl, @NonNull @NonNull String username, @NonNull @NonNull String password, @NonNull @NonNull String jwtTokenEndPoint)
      Creates a builder configured for JWT-based authentication.

      The client obtains JWT tokens from the supplied token endpoint using the provided credentials.

      Parameters:
      baseUrl - Base URL of the WordPress instance.
      username - Username used to obtain JWT tokens.
      password - Password used to obtain JWT tokens.
      jwtTokenEndPoint - endpoint for the JWT token, relative to API-URL; must not be blank
      Returns:
      A new builder instance.