- All Superinterfaces:
org.mule.runtime.api.lifecycle.Startable,org.mule.runtime.api.lifecycle.Stoppable
@Experimental
@NoImplement
@MinMuleVersion("4.10.0")
public interface HttpClient
extends org.mule.runtime.api.lifecycle.Startable, org.mule.runtime.api.lifecycle.Stoppable
Object to send HTTP requests. Notice it must be started to be used and stopped to be disposed properly.
- Since:
- 0.12.0
-
Field Summary
Fields inherited from interface org.mule.runtime.api.lifecycle.Startable
PHASE_NAMEFields inherited from interface org.mule.runtime.api.lifecycle.Stoppable
PHASE_NAME -
Method Summary
Modifier and TypeMethodDescriptionsendAsync(HttpRequest request, Consumer<HttpRequestOptionsConfigurer> options) Sends an HttpRequest without blocking the current thread.sseSource(Consumer<SseSourceConfigurer> configConsumer) Creates a consumer of Server-sent events.Methods inherited from interface org.mule.runtime.api.lifecycle.Startable
startMethods inherited from interface org.mule.runtime.api.lifecycle.Stoppable
stop
-
Method Details
-
sendAsync
CompletableFuture<HttpResponse> sendAsync(HttpRequest request, Consumer<HttpRequestOptionsConfigurer> options) Sends an HttpRequest without blocking the current thread. When a response is available or the request times out, the returnedCompletableFuturewill be completed. Be aware that the response body processing will be deferred so that the response can be processed even when a large body is still being received. If the full response is needed right away then the providedHttpResponsemust be read in a different thread so that it does not block theHttpClientthreads handling the response. It's therefore any of the async methods available, such asCompletableFuture.whenCompleteAsync(BiConsumer, Executor), to handle the response is those scenarios since they guarantee executing on a different thread.- Parameters:
request- theHttpRequestto sendoptions- a callback to configure the request options.- Returns:
- a
CompletableFuturethat will complete once theHttpResponseis available
-
sseSource
Creates a consumer of Server-sent events. The resultingSseSourceis not connected automatically.- Parameters:
configConsumer- a callback to configure the resulting source.- Returns:
- a non-connected instance of
SseSource.
-