APIdia Launch Partner
Top Description Interfaces Classes
module java.net.http

Package java.net.http

Imports
java.lang.UnsupportedOperationException, java.net.http.HttpClient, .HttpRequest, .HttpResponse.BodyHandler, java.util.concurrent.CompletableFuture

HTTP Client and WebSocket APIs

Provides high-level client interfaces to HTTP (versions 1.1, 2, and 3) and low-level client interfaces to WebSocket. The main types defined are:

The protocol-specific requirements are defined in the Hypertext Transfer Protocol Version 3 (HTTP/3), the Hypertext Transfer Protocol Version 2 (HTTP/2), the Hypertext Transfer Protocol (HTTP/1.1), and The WebSocket Protocol.

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 obtrudeValue and obtrudeException methods. Unless otherwise specified, 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 NullPointerException.

Since
11
External Specification
https://www.rfc-editor.org/info/rfc9114, https://www.rfc-editor.org/info/rfc7540, https://www.rfc-editor.org/info/rfc2616, https://www.rfc-editor.org/info/rfc6455
See Also
java.net.http/

Interface Summary

Modifier and TypeInterface and Description
public interface
HttpOption<T>

This interface is used to provide additional request configuration option hints on how an HTTP request/response exchange should be carried out by the HttpClient implementation.

public interface
HttpResponse<
the response body type
T
>

An HTTP response.

public interface
WebSocket

A WebSocket Client.

Class Summary

Modifier and TypeClass and Description
public abstract class
HttpClient

An HTTP Client.

public class
HttpConnectTimeoutException

Thrown when a connection, over which an HttpRequest is intended to be sent, is not successfully established within a specified time period.

public class
HttpHeaders

A read-only view of a set of HTTP headers.

public abstract class
HttpRequest

An HTTP request.

public class
HttpTimeoutException

Thrown when a response is not received within a specified time period.

public class
StreamLimitException

An exception raised when the limit imposed for stream creation on an HTTP connection is reached, and the client is unable to create a new stream.

public class
UnsupportedProtocolVersionException

Thrown when the HTTP client doesn't support a particular HTTP version.

public class
WebSocketHandshakeException

Thrown when the opening handshake has failed.