Class HttpClient

java.lang.Object
masecla.modrinth4j.client.HttpClient
Direct Known Subclasses:
RatelimitedHttpClient, UnlimitedHttpClient

public abstract class HttpClient extends Object
This class is used to connect to the Modrinth API.
  • Constructor Details

    • HttpClient

      public HttpClient(UserAgent userAgent, String apiKey)
      Creates a new instance of the client.
      Parameters:
      userAgent - The user agent to use.
      apiKey - The API key to use.
    • HttpClient

      public HttpClient(UserAgent userAgent, String baseUrl, String apiKey)
      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

      public HttpClient(UserAgent userAgent, String baseUrl, String apiKey, long timeout)
      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

      public CompletableFuture<okhttp3.Request.Builder> connect(String url)
      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

      public okhttp3.Response execute(okhttp3.Request.Builder connection) throws IOException
      Executes a request.
      Parameters:
      connection - - The connection to execute.
      Returns:
      The response.
      Throws:
      IOException - If an error occurs.
    • nextRequest

      public abstract CompletableFuture<Void> 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.