Package masecla.modrinth4j.client
Class HttpClient
java.lang.Object
masecla.modrinth4j.client.HttpClient
- Direct Known Subclasses:
RatelimitedHttpClient,UnlimitedHttpClient
This class is used to connect to the Modrinth API.
-
Constructor Summary
ConstructorsConstructorDescriptionHttpClient(UserAgent userAgent, String apiKey) Creates a new instance of the client.HttpClient(UserAgent userAgent, String baseUrl, String apiKey) Creates a new instance of the client.HttpClient(UserAgent userAgent, String baseUrl, String apiKey, long timeout) Creates a new instance of the client. -
Method Summary
Modifier and TypeMethodDescriptionCompletableFuture<okhttp3.Request.Builder> Creates a new connection to the API.CompletableFuture<okhttp3.Request.Builder> Creates a new connection to the API.okhttp3.Responseexecute(okhttp3.Request.Builder connection) Executes a request.voidinterceptResponse(okhttp3.Response response) Intercepts a response.abstract CompletableFuture<Void> Waits for the next request to be allowed.
-
Constructor Details
-
HttpClient
Creates a new instance of the client.- Parameters:
userAgent- The user agent to use.apiKey- The API key to use.
-
HttpClient
Creates a new instance of the client.- Parameters:
userAgent- The user agent to use.baseUrl- The base URL to use.apiKey- The API key to use.
-
HttpClient
Creates a new instance of the client.- Parameters:
userAgent- The user agent to use.baseUrl- The base URL to use.apiKey- The API key to use.timeout- The timeout to use.
-
-
Method Details
-
connect
Creates a new connection to the API.- Parameters:
url- - The URL to connect to.- Returns:
- The connection.
-
connect
public CompletableFuture<okhttp3.Request.Builder> connect(String url, Map<String, String> queryParams) Creates a new connection to the API.- Parameters:
url- - The URL to connect to.queryParams- - The query parameters to use.- Returns:
- The connection.
-
execute
Executes a request.- Parameters:
connection- - The connection to execute.- Returns:
- The response.
- Throws:
IOException- If an error occurs.
-
nextRequest
Waits for the next request to be allowed.- Returns:
- A future that completes when the next request is allowed.
-
interceptResponse
public void interceptResponse(okhttp3.Response response) Intercepts a response.- Parameters:
response- - The response to intercept.
-