Package com.petarmc.petarlib.net
Class HttpClientWrapper
java.lang.Object
com.petarmc.petarlib.net.HttpClientWrapper
A simple wrapper around Java's HttpClient with support for retries and asycn execution.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new HttpClientWrapper with a default maximum number of retries from the plugin config.HttpClientWrapper(int maxRetries) Creates a new HttpClientWrapper with a specified maximum number of retries. -
Method Summary
Modifier and TypeMethodDescriptionSends an async GET request to the specified URL.post(HttpRequest request) Sends an async POST request using the provided HttpRequest.voidshutdown()Shuts down the executor used for async HTTP requests.
-
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
Sends an async GET request to the specified URL.- Parameters:
url- the target URL- Returns:
- a CompletableFuture containing the response body
-
post
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.
-