Class HttpGet

java.lang.Object
me.pauleff.common.handlers.http.HttpGet

public final class HttpGet extends Object
Sends HTTP GET requests and returns successful response bodies.

Prefer the static one-shot body(String) for simple calls. Use of(HttpClient) when injecting a custom client (for example in tests).

  • Method Details

    • ofDefault

      public static HttpGet ofDefault()
      Returns a handle that uses the shared default HttpClient.
      Returns:
      the default HTTP GET client
    • of

      public static HttpGet of(HttpClient client)
      Returns a handle that uses the given HttpClient.
      Parameters:
      client - the HTTP client to send requests with
      Returns:
      an HTTP GET handle
      Throws:
      NullPointerException - if client is null
    • body

      public static String body(String url) throws IOException
      Sends an HTTP GET request with the default client and returns the body on success.
      Parameters:
      url - the absolute URL to request
      Returns:
      the response body if the status code is 200; null otherwise
      Throws:
      IOException - if the request fails or is interrupted
    • getBody

      public String getBody(String url) throws IOException
      Sends an HTTP GET request to the given URL and returns the response body on success.
      Parameters:
      url - the absolute URL to request
      Returns:
      the response body if the status code is 200; null otherwise
      Throws:
      NullPointerException - if url is null
      IOException - if the request fails or is interrupted