Class: HttpClient

vertx/http. HttpClient

new HttpClient()

An HTTP client that maintains a pool of connections to a specific host, at a specific port. The client supports pipelining of requests.

As well as HTTP requests, the client can act as a factory for HTML5 websockets.

Source:

Extends

Methods

close()

Close the client
Source:

connect(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP CONNECT request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the CONNECT on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

connectWebsocket(uri, handler)

Attempt to connect an HTML5 websocket to the specified URI. The connect is done asynchronously and the handler is called with a WebSocket on success.
Parameters:
Name Type Description
uri string A relative URI where to connect the websocket on the host, e.g. /some/path
handler WebSocketHandler The handler to be called with the WebSocket
Source:

delete(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP DELETE request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the DELETE on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

exceptionHandler(handler) → {module:vertx/http.HttpClient}

Set the exception handler.
Parameters:
Name Type Description
handler Handler The handler which is called on an exception
Source:
Returns:
Type
module:vertx/http.HttpClient

get(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP GET request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the GET on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

getNow(uri, handler) → {module:vertx/http.HttpClientRequest}

This is a quick version of the get method where you do not want to do anything with the request before sing. With this method the request is immediately sent. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the GET on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest
This method returns an request which represents an HTTP HEAD request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the HEAD on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

host(host) → {string|module:vertx/http.HttpClient}

Get or set the host name or ip address that the client will attempt to connect to on the server on
Parameters:
Name Type Argument Description
host string <optional>
The host name or IP address.
Source:
Returns:
Type
string | module:vertx/http.HttpClient

keepAlive(keepAlive) → {boolean|module:vertx/http.HttpClient}

Get or set if the client use keep alive. If keepAlive is true then, after the request has ended the connection will be returned to the pool where it can be used by another request. In this manner, many HTTP requests can be pipe-lined over an HTTP connection. Keep alive connections will not be closed until the close() method is invoked.

If keepAlive is false then a new connection will be created for each request and it won't ever go in the pool, and the connection will closed after the response has been received. Even with no keep alive, the client will not allow more than getMaxPoolSize() connections to be created at any one time.

If keepAlive is undefined returns the current keep alive status of this client.

Parameters:
Name Type Argument Description
keepAlive boolean <optional>
Source:
Returns:
Type
boolean | module:vertx/http.HttpClient

keyStorePassword(password) → {boolean|Object}

Get or set the current keystore password for this object.
Parameters:
Name Type Argument Description
password string <optional>
If provided, sets the keystore password
Inherited From:
Source:
Returns:
the current password, or this.
Type
boolean | Object

keyStorePath(path) → {boolean|Object}

Get or set the current keystore path for this object.
Parameters:
Name Type Argument Description
path string <optional>
If provided, sets the keystore path
Inherited From:
Source:
Returns:
the current path, or this.
Type
boolean | Object

maxPoolSize(size) → {number|module:vertx/http.HttpClient}

Get or set the maxium number of connections this client will pool
Parameters:
Name Type Argument Description
size number <optional>
the maximum number of connection
Source:
Returns:
Type
number | module:vertx/http.HttpClient

maxWebSocketFrameSize(size)

Set or get the maximum frame size for websocket connections exposed over the SockJS bridge with this HTTPClient
Parameters:
Name Type Argument Description
size number <optional>
The frame size in bytes
Source:

options(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP OPTIONS request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the OPTIONS on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

patch(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP PATCH request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the PATCH on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

port(port) → {number|module:vertx/http.HttpClient}

Get or set the port that the client will attempt to connect to on the server on. The default value is 80
Parameters:
Name Type Argument Description
port number <optional>
The port to connect on.
Source:
Returns:
Type
number | module:vertx/http.HttpClient

post(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP POST request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the POST on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

put(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP PUT request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the PUT on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

receiveBufferSize(size) → {number|Object}

Set or get the receive buffer size
Parameters:
Name Type Argument Description
size number <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
number | Object

request(method, uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
method string The HTTP method which is used for the request
uri string A relative URI where to perform the PUT on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

reuseAddress(reuse) → {boolean|Object}

Set or get the TCP reuse address value
Parameters:
Name Type Argument Description
reuse boolean <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
boolean | Object

sendBufferSize(size) → {number|Object}

Set or get the send buffer size
Parameters:
Name Type Argument Description
size number <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
number | Object

soLinger(linger) → {boolean|Object}

Set or get the TCP so linger value
Parameters:
Name Type Argument Description
linger boolean <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
boolean | Object

ssl(ssl) → {boolean|Object}

Get or set the current SSL support for this object.
Parameters:
Name Type Argument Description
ssl boolean <optional>
If provided, sets whether this object supports SSL
Inherited From:
Source:
Returns:
the current status, or this.
Type
boolean | Object

tcpKeepAlive(keepAlive) → {boolean|Object}

Set or get the TCP keep-alive value
Parameters:
Name Type Argument Description
keepAlive boolean <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
boolean | Object

tcpNoDelay(nodelay) → {boolean|Object}

Set or get the TCP no delay value.
Parameters:
Name Type Argument Description
nodelay boolean <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
boolean | Object

trace(uri, handler) → {module:vertx/http.HttpClientRequest}

This method returns an request which represents an HTTP TRACE request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.
Parameters:
Name Type Description
uri string A relative URI where to perform the TRACE on the server.
handler ResponseHandler The handler to be called
Source:
Returns:
Type
module:vertx/http.HttpClientRequest

trafficClass(class) → {number|Object}

Set or get the TCP traffic class
Parameters:
Name Type Argument Description
class number <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
number | Object

trustAll(all) → {boolean|Object}

Get or set the trustAll SSL attribute
Parameters:
Name Type Argument Description
all boolean <optional>
If provided, sets the trustAll attribute
Inherited From:
Source:
Returns:
the current trustAll status, or this
Type
boolean | Object

trustStorePassword(password) → {boolean|Object}

Get or set the current trust store password for this object.
Parameters:
Name Type Argument Description
password string <optional>
If provided, sets the trust store password
Inherited From:
Source:
Returns:
the current password, or this.
Type
boolean | Object

trustStorePath(path) → {boolean|Object}

Get or set the current trust store path for this object.
Parameters:
Name Type Argument Description
path string <optional>
If provided, sets the trust store path
Inherited From:
Source:
Returns:
the current path, or this.
Type
boolean | Object

tryUseCompression(shouldTry) → {boolean|module:vertx/http.HttpClient}

Set or get whether the client should try to use compression
Parameters:
Name Type Argument Description
shouldTry boolean <optional>
Whether the client should try to use compression
Source:
Returns:
Whether compression is tried or self
Type
boolean | module:vertx/http.HttpClient

usePooledBuffers(use) → {boolean|Object}

Set or get if vertx should use pooled buffers for performance reasons. Doing so will give the best throughput but may need a bit higher memory footprint.
Parameters:
Name Type Argument Description
use boolean <optional>
If provided, set the value; if not, returns the current value.
Inherited From:
Source:
Returns:
the value or this
Type
boolean | Object

verifyHost(verify) → {boolean|module:vertx/http.HttpClient}

Get or set if the host should be verified. If set then the client will try to validate the remote server's certificate hostname against the requested host. Should default to 'true'. This method should only be used in SSL mode
Parameters:
Name Type Description
verify boolean whether or not to verify hosts
Source:
Returns:
Type
boolean | module:vertx/http.HttpClient