HTTP Client and WebSocket APIs
Provides high-level client interfaces to HTTP (versions 1.1 and 2) and low-level client interfaces to WebSocket. The main types defined are:
In general, asynchronous tasks execute in either the thread invoking
the operation, e.g. sending an HTTP request, or by the threads supplied by the client's
executor. Dependent tasks, those that are triggered by
returned CompletionStages or CompletableFutures, that do not explicitly
specify an executor, execute in the same
default executor as that of
CompletableFuture, or the invoking thread if the operation completes before
the dependent task is registered.
CompletableFutures returned by this API will throw
UnsupportedOperationException for their
obtrudeException methods. Invoking the
cancel method on a
CompletableFuture returned by this API may not
interrupt the underlying operation, but may be useful to complete,
exceptionally, dependent stages that have not already completed.
Unless otherwise stated,
null parameter values will cause methods
of all classes in this package to throw
Interface Summary Interface Description HttpClient.BuilderA builder of HTTP Clients. HttpRequest.BodyPublisherA
BodyPublisherconverts high-level Java objects into a flow of byte buffers suitable for sending as a request body.
HttpRequest.BuilderA builder of HTTP requests. HttpResponse<T>An HTTP response. HttpResponse.BodyHandler<T>A handler for response bodies. HttpResponse.BodySubscriber<T>A
BodySubscriberconsumes response body bytes and converts them into a higher-level Java type.
HttpResponse.PushPromiseHandler<T>A handler for push promises. HttpResponse.ResponseInfoInitial response information supplied to a
BodyHandlerwhen a response is initially received and before the body is processed.
WebSocketA WebSocket Client. WebSocket.BuilderA builder of WebSocket Clients. WebSocket.ListenerThe receiving interface of
Class Summary Class Description HttpClientAn HTTP Client. HttpHeadersA read-only view of a set of HTTP headers. HttpRequestAn HTTP request. HttpRequest.BodyPublishersImplementations of
BodyPublisherthat implement various useful publishers, such as publishing the request body from a String, or from a file.
BodyHandlerthat implement various useful handlers, such as handling the response body as a String, or streaming the response body to a file.
BodySubscriberthat implement various useful subscribers, such as converting the response body bytes into a String, or streaming the bytes to a file.
Enum Summary Enum Description HttpClient.RedirectDefines the automatic redirection policy. HttpClient.VersionThe HTTP protocol version.
Exception Summary Exception Description HttpTimeoutExceptionThrown when a response is not received within a specified time period. WebSocketHandshakeExceptionThrown when the opening handshake has failed.