Interface HttpClient

All Known Implementing Classes:
JdkHttpClient, LoggingHttpClient

public interface HttpClient
A client for executing HTTP requests both synchronously and asynchronously. This interface is currently experimental and subject to change.
  • Method Details

    • execute

      Executes a given HTTP request synchronously and returns the response. This method blocks until the entire response is received.
      Parameters:
      request - the HTTP request to be executed.
      Returns:
      a SuccessfulHttpResponse containing the response data for successful HTTP requests (2XX status codes)
      Throws:
      HttpException - if the server returns a client (4XX) or server (5XX) error response
      RuntimeException - if an unexpected error occurs during request execution (e.g., network issues, timeouts)
    • execute

      void execute(HttpRequest request, ServerSentEventParser parser, ServerSentEventListener listener)
      Executes a given HTTP request asynchronously with server-sent events (SSE) handling. This method returns immediately while processing continues on a separate thread. Events are processed through the provided ServerSentEventListener.

      The execution flow is as follows:

      1. The request is initiated asynchronously
      2. Received SSE data is parsed using the provided parser
      3. Parsed events are delivered to the listener's appropriate methods
      4. If an error occurs, ServerSentEventListener.onError(Throwable) is called

      If any exception is thrown from the listener's methods, the stream processing will be terminated and no further events will be processed.

      Parameters:
      request - the HTTP request to be executed.
      parser - the parser to process incoming server-sent events.
      listener - the listener to receive parsed events and error notifications.