Interface HTTPClient

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
RecordingClient, SpeakeasyHTTPClient

public interface HTTPClient extends AutoCloseable
  • Method Details

    • close

      default void close() throws Exception
      Releases resources owned by this client.

      The default is a no-op so custom implementations that borrow an externally owned client are not forced to tear down resources they do not own. Implementations that own resources should override this method.

      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception - if an owned resource cannot be released
    • send

      Sends an HTTP request and returns the response.

      Note that HttpRequest is immutable. To modify the request use HttpRequest.toBuilder() which copies the request into a builder.

      Parameters:
      request - HTTP request
      Returns:
      HTTP response
      Throws:
      IOException
    • sendAsync

      Sends an HTTP request asynchronously and returns a response whose body is exposed as an InputStream (the same body type as the synchronous send(HttpRequest)).

      The request is dispatched without blocking the calling thread. The returned CompletableFuture completes when the response headers are received — the body is not read at that point — 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 an InputStream 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