Top Description Methods
io.vertx.core.http

public Interface HttpClient

extends Measured
Known Direct Subinterfaces
io.vertx.core.http.impl.HttpClientInternal
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.Fluent, .GenIgnore, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, .MultiMap, io.vertx.core.metrics.Measured, io.vertx.core.net.SSLOptions, java.util.List, java.util.function.Function

An asynchronous HTTP client.

It allows you to make requests to HTTP servers, and a single client can make requests to any server.

This gives the benefits of keep alive when the client is loaded but means we don't keep connections hanging around unnecessarily when there would be no benefits anyway.

The client is designed to be reused between requests.

Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public void
close(Handler<AsyncResult<Void>> handler)

Close the client.

public Future<Void>
close()

Like close(Handler) but returns a Future of the asynchronous result

public HttpClient

Returns:

a reference to this, so the API can be used fluently
connectionHandler
(Handler<HttpConnection> handler)

Set a connection handler for the client.

public HttpClient

Returns:

a reference to this, so the API can be used fluently
redirectHandler
(Function<HttpClientResponse, Future<RequestOptions>>
the new redirect handler
handler
)

Set a redirect handler for the http client.

public Function<HttpClientResponse, Future<RequestOptions>>

Returns:

the current redirect handler.
redirectHandler
()
Deprecated

public void
request(RequestOptions
the request options
options
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Create an HTTP request to send to the server.

public Future<HttpClientRequest>
request(RequestOptions options)

Like request(RequestOptions, Handler) but returns a Future of the asynchronous result

public void
request(HttpMethod
the HTTP method
method
,
int
the port
port
,
String
the host
host
,
String
the relative URI
requestURI
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Create an HTTP request to send to the server at the host and port.

public default Future<HttpClientRequest>
request(HttpMethod method, int port, String host, String requestURI)

Like request(HttpMethod, int, String, String, Handler) but returns a Future of the asynchronous result

public void
request(HttpMethod
the HTTP method
method
,
String
the host
host
,
String
the relative URI
requestURI
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Create an HTTP request to send to the server at the host and default port.

public default Future<HttpClientRequest>
request(HttpMethod method, String host, String requestURI)

Like request(HttpMethod, String, String, Handler) but returns a Future of the asynchronous result

public void
request(HttpMethod
the HTTP method
method
,
String
the relative URI
requestURI
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Create an HTTP request to send to the server at the default host and port.

public default Future<HttpClientRequest>
request(HttpMethod method, String requestURI)

Like request(HttpMethod, String, Handler) but returns a Future of the asynchronous result

public default Future<Boolean>

Returns:

a future signaling the update success
updateSSLOptions
(SSLOptions
the new SSL options
options
)

Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

public default void
updateSSLOptions(SSLOptions
the new SSL options
options
,
Handler<AsyncResult<Boolean>>
the update handler
handler
)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

public Future<Boolean>

Returns:

a future signaling the update success
updateSSLOptions
(SSLOptions
the new SSL options
options
,
boolean
force the update when options are equals
force
)

Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

public default void
updateSSLOptions(SSLOptions
the new SSL options
options
,
boolean
force the update when options are equals
force
,
Handler<AsyncResult<Boolean>>
the update handler
handler
)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

public void
webSocket(int
the port
port
,
String
the host
host
,
String
the relative URI
requestURI
,
Handler<AsyncResult<WebSocket>>
handler that will be called with the WebSocket when connected
handler
)

Connect a WebSocket to the specified port, host and relative request URI

public Future<WebSocket>
webSocket(int port, String host, String requestURI)

Like webSocket(int, String, String, Handler) but returns a Future of the asynchronous result

public void
webSocket(String
the host
host
,
String
the relative URI
requestURI
,
Handler<AsyncResult<WebSocket>>
handler that will be called with the WebSocket when connected
handler
)

Connect a WebSocket to the host and relative request URI and default port

public Future<WebSocket>
webSocket(String host, String requestURI)

Like webSocket(String, String, Handler) but returns a Future of the asynchronous result

public void
webSocket(String
the relative URI
requestURI
,
Handler<AsyncResult<WebSocket>>
handler that will be called with the WebSocket when connected
handler
)

Connect a WebSocket at the relative request URI using the default host and port

public Future<WebSocket>
webSocket(String requestURI)

Like webSocket(String, Handler) but returns a Future of the asynchronous result

public void
webSocket(WebSocketConnectOptions
the request options
options
,
Handler<AsyncResult<WebSocket>> handler)

Connect a WebSocket with the specified options.

public Future<WebSocket>
webSocket(WebSocketConnectOptions options)

Like webSocket(WebSocketConnectOptions, Handler) but returns a Future of the asynchronous result

public void
webSocketAbs(String
the absolute url
url
,
MultiMap
the headers
headers
,
WebsocketVersion
the WebSocket version
version
,
List<String>
the subprotocols to use
subProtocols
,
Handler<AsyncResult<WebSocket>>
handler that will be called if WebSocket connection fails
handler
)

Connect a WebSocket with the specified absolute url, with the specified headers, using the specified version of WebSockets, and the specified WebSocket sub protocols.

public Future<WebSocket>
webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols)

Like webSocketAbs(String, MultiMap, WebsocketVersion, List, Handler) but returns a Future of the asynchronous result

Inherited from io.vertx.core.metrics.Measured:
isMetricsEnabled

Method Detail

closeback to summary
public void close(Handler<AsyncResult<Void>> handler)

Close the client. Closing will close down any pooled connections. Clients should always be closed after use.

closeback to summary
public Future<Void> close()

Like close(Handler) but returns a Future of the asynchronous result

connectionHandlerback to summary
public HttpClient connectionHandler(Handler<HttpConnection> handler)

Set a connection handler for the client. This handler is called when a new connection is established.

Returns:HttpClient

a reference to this, so the API can be used fluently

Annotations
@Deprecated
@Fluent
redirectHandlerback to summary
public HttpClient redirectHandler(Function<HttpClientResponse, Future<RequestOptions>> handler)

Set a redirect handler for the http client.

The redirect handler is called when a 3xx response is received and the request is configured to follow redirects with HttpClientRequest#setFollowRedirects(boolean).

The redirect handler is passed the HttpClientResponse, it can return an HttpClientRequest or null.

  • when null is returned, the original response is processed by the original request response handler
  • when a new Future<HttpClientRequest> is returned, the client will send this new request
The new request will get a copy of the previous request headers unless headers are set. In this case, the client assumes that the redirect handler exclusively managers the headers of the new request.

The handler must return a Future<HttpClientRequest> unsent so the client can further configure it and send it.

Parameters
handler:Function<HttpClientResponse, Future<RequestOptions>>

the new redirect handler

Returns:HttpClient

a reference to this, so the API can be used fluently

Annotations
@Deprecated
@Fluent
redirectHandlerback to summary
public Function<HttpClientResponse, Future<RequestOptions>> redirectHandler()

Deprecated

Returns:Function<HttpClientResponse, Future<RequestOptions>>

the current redirect handler.

Annotations
@Deprecated
@GenIgnore
requestback to summary
public void request(RequestOptions options, Handler<AsyncResult<HttpClientRequest>> handler)

Create an HTTP request to send to the server. The handler is called when the request is ready to be sent.

Parameters
options:RequestOptions

the request options

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

requestback to summary
public Future<HttpClientRequest> request(RequestOptions options)

Like request(RequestOptions, Handler) but returns a Future of the asynchronous result

requestback to summary
public void request(HttpMethod method, int port, String host, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)

Create an HTTP request to send to the server at the host and port. The handler is called when the request is ready to be sent.

Parameters
method:HttpMethod

the HTTP method

port:int

the port

host:String

the host

requestURI:String

the relative URI

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

requestback to summary
public default Future<HttpClientRequest> request(HttpMethod method, int port, String host, String requestURI)

Like request(HttpMethod, int, String, String, Handler) but returns a Future of the asynchronous result

requestback to summary
public void request(HttpMethod method, String host, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)

Create an HTTP request to send to the server at the host and default port. The handler is called when the request is ready to be sent.

Parameters
method:HttpMethod

the HTTP method

host:String

the host

requestURI:String

the relative URI

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

requestback to summary
public default Future<HttpClientRequest> request(HttpMethod method, String host, String requestURI)

Like request(HttpMethod, String, String, Handler) but returns a Future of the asynchronous result

requestback to summary
public void request(HttpMethod method, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)

Create an HTTP request to send to the server at the default host and port. The handler is called when the request is ready to be sent.

Parameters
method:HttpMethod

the HTTP method

requestURI:String

the relative URI

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

requestback to summary
public default Future<HttpClientRequest> request(HttpMethod method, String requestURI)

Like request(HttpMethod, String, Handler) but returns a Future of the asynchronous result

updateSSLOptionsback to summary
public default Future<Boolean> updateSSLOptions(SSLOptions options)

Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

The boolean succeeded future result indicates whether the update occurred.

Parameters
options:SSLOptions

the new SSL options

Returns:Future<Boolean>

a future signaling the update success

updateSSLOptionsback to summary
public default void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

Parameters
options:SSLOptions

the new SSL options

handler:Handler<AsyncResult<Boolean>>

the update handler

updateSSLOptionsback to summary
public Future<Boolean> updateSSLOptions(SSLOptions options, boolean force)

Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

The boolean succeeded future result indicates whether the update occurred.

Parameters
options:SSLOptions

the new SSL options

force:boolean

force the update when options are equals

Returns:Future<Boolean>

a future signaling the update success

updateSSLOptionsback to summary
public default void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler)

Like updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update happened (or has failed).

Parameters
options:SSLOptions

the new SSL options

force:boolean

force the update when options are equals

handler:Handler<AsyncResult<Boolean>>

the update handler

webSocketback to summary
public void webSocket(int port, String host, String requestURI, Handler<AsyncResult<WebSocket>> handler)

Connect a WebSocket to the specified port, host and relative request URI

Parameters
port:int

the port

host:String

the host

requestURI:String

the relative URI

handler:Handler<AsyncResult<WebSocket>>

handler that will be called with the WebSocket when connected

Annotations
@Deprecated
webSocketback to summary
public Future<WebSocket> webSocket(int port, String host, String requestURI)

Like webSocket(int, String, String, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated
webSocketback to summary
public void webSocket(String host, String requestURI, Handler<AsyncResult<WebSocket>> handler)

Connect a WebSocket to the host and relative request URI and default port

Parameters
host:String

the host

requestURI:String

the relative URI

handler:Handler<AsyncResult<WebSocket>>

handler that will be called with the WebSocket when connected

Annotations
@Deprecated
webSocketback to summary
public Future<WebSocket> webSocket(String host, String requestURI)

Like webSocket(String, String, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated
webSocketback to summary
public void webSocket(String requestURI, Handler<AsyncResult<WebSocket>> handler)

Connect a WebSocket at the relative request URI using the default host and port

Parameters
requestURI:String

the relative URI

handler:Handler<AsyncResult<WebSocket>>

handler that will be called with the WebSocket when connected

Annotations
@Deprecated
webSocketback to summary
public Future<WebSocket> webSocket(String requestURI)

Like webSocket(String, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated
webSocketback to summary
public void webSocket(WebSocketConnectOptions options, Handler<AsyncResult<WebSocket>> handler)

Connect a WebSocket with the specified options.

Parameters
options:WebSocketConnectOptions

the request options

Annotations
@Deprecated
webSocketback to summary
public Future<WebSocket> webSocket(WebSocketConnectOptions options)

Like webSocket(WebSocketConnectOptions, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated
webSocketAbsback to summary
public void webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols, Handler<AsyncResult<WebSocket>> handler)

Connect a WebSocket with the specified absolute url, with the specified headers, using the specified version of WebSockets, and the specified WebSocket sub protocols.

Parameters
url:String

the absolute url

headers:MultiMap

the headers

version:WebsocketVersion

the WebSocket version

subProtocols:List<String>

the subprotocols to use

handler:Handler<AsyncResult<WebSocket>>

handler that will be called if WebSocket connection fails

Annotations
@Deprecated
webSocketAbsback to summary
public Future<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols)

Like webSocketAbs(String, MultiMap, WebsocketVersion, List, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated