Interface HTTPClient

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.net.http.HttpClient client  
    • Method Summary

      All Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default void enableDebugLogging​(boolean enabled)
      Controls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses.
      default boolean isDebugLoggingEnabled()
      Returns whether debug logging is enabled.
      default java.net.http.HttpResponse<java.io.InputStream> send​(java.net.http.HttpRequest request)
      Sends an HTTP request and returns the response.
      default java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> sendAsync​(java.net.http.HttpRequest request)
      Sends an HTTP request asynchronously and returns a response whose body is exposed as a Blob.
    • Field Detail

      • client

        static final java.net.http.HttpClient client
    • Method Detail

      • send

        default java.net.http.HttpResponse<java.io.InputStream> send​(java.net.http.HttpRequest request)
                                                              throws java.io.IOException,
                                                                     java.lang.InterruptedException,
                                                                     java.net.URISyntaxException
        Sends an HTTP request and returns the response.

        Note that HttpRequest is immutable. To modify the request you can use HttpRequest#newBuilder(HttpRequest, BiPredicate<String, String>) with JDK 16 and later (which will copy the request for modification in a builder). If that method is not available then use Helpers.copy(java.net.http.HttpRequest) (which also returns a builder).

        Parameters:
        request - HTTP request
        Returns:
        HTTP response
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.net.URISyntaxException
      • sendAsync

        default java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> sendAsync​(java.net.http.HttpRequest request)
        Sends an HTTP request asynchronously and returns a response whose body is exposed as a Blob.

        This method uses the HttpResponse.BodyHandlers.ofPublisher() to obtain the response body as a Flow.Publisher<List<ByteBuffer>>, which is then wrapped in a Blob for non-blocking, reactive consumption of the response data.

        The returned CompletableFuture completes when the response is received, or completes exceptionally if an error occurs during the request or response processing.

        Parameters:
        request - the HTTP request to send
        Returns:
        a CompletableFuture containing the HTTP response with a Blob body
      • enableDebugLogging

        default void enableDebugLogging​(boolean enabled)
        Controls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses. This is currently implemented in SpeakeasyHTTPClient but custom client implementations are free to use this method similarly if they wish.
        Parameters:
        enabled - Whether to enable debug flag
      • isDebugLoggingEnabled

        default boolean isDebugLoggingEnabled()
        Returns whether debug logging is enabled.
        Returns:
        Whether debug logging is enabled