Class HttpClientWrapper

java.lang.Object
com.petarmc.petarlib.net.HttpClientWrapper

public class HttpClientWrapper extends Object
A simple wrapper around Java's HttpClient with support for retries and asycn execution.
  • Constructor Details

    • HttpClientWrapper

      public HttpClientWrapper()
      Creates a new HttpClientWrapper with a default maximum number of retries from the plugin config. Callers can use the no-arg constructor to pick up the default, or the (int) constructor to override it.
    • HttpClientWrapper

      public HttpClientWrapper(int maxRetries)
      Creates a new HttpClientWrapper with a specified maximum number of retries.
      Parameters:
      maxRetries - maximum number of attempts for failed reqs, minimum 1. A default value can be set in the plugin's config.yml
  • Method Details

    • get

      public CompletableFuture<String> get(String url)
      Sends an async GET request to the specified URL.
      Parameters:
      url - the target URL
      Returns:
      a CompletableFuture containing the response body
    • post

      public CompletableFuture<String> post(HttpRequest request)
      Sends an async POST request using the provided HttpRequest.
      Parameters:
      request - the HttpRequest to send
      Returns:
      a CompletableFuture containing the response body
    • shutdown

      public void shutdown()
      Shuts down the executor used for async HTTP requests.