new HttpClient()
An asynchronous HTTP client.
It allows you to make requests to HTTP servers, and a single client can make requests to any server.
It also allows you to open WebSockets to servers.
The client can also pool HTTP connections.
- Source:
Methods
close()
Close the client. Closing will close down any pooled connections.
Clients should always be closed after use.
- Source:
connectionHandler(handler) → {HttpClient}
Set a connection handler for the client. This handler is called when a new connection is established.
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- HttpClient
delete(requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP DELETE request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
deleteAbs(absoluteURI, responseHandler) → {HttpClientRequest}
Create an HTTP DELETE request to send to the server using an absolute URI, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
absoluteURI |
string | the absolute URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
get(requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP GET request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
getAbs(absoluteURI, responseHandler) → {HttpClientRequest}
Create an HTTP GET request to send to the server using an absolute URI, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
absoluteURI |
string | the absolute URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
getNow(requestURI, responseHandler) → {HttpClient}
Sends an HTTP GET request to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- HttpClient
head(requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP HEAD request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
headAbs(absoluteURI, responseHandler) → {HttpClientRequest}
Create an HTTP HEAD request to send to the server using an absolute URI, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
absoluteURI |
string | the absolute URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
headNow(requestURI, responseHandler) → {HttpClient}
Sends an HTTP HEAD request to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- HttpClient
isMetricsEnabled() → {boolean}
Whether the metrics are enabled for this measured object
- Source:
Returns:
true if metrics are enabled
- Type
- boolean
options(requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP OPTIONS request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
optionsAbs(absoluteURI, responseHandler) → {HttpClientRequest}
Create an HTTP OPTIONS request to send to the server using an absolute URI, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
absoluteURI |
string | the absolute URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
optionsNow(requestURI, responseHandler) → {HttpClient}
Sends an HTTP OPTIONS request to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- HttpClient
post(requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP POST request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
postAbs(absoluteURI, responseHandler) → {HttpClientRequest}
Create an HTTP POST request to send to the server using an absolute URI, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
absoluteURI |
string | the absolute URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
put(requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP PUT request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
putAbs(absoluteURI, responseHandler) → {HttpClientRequest}
Create an HTTP PUT request to send to the server using an absolute URI, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
absoluteURI |
string | the absolute URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
redirectHandler(handler) → {HttpClient}
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.
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
Futureis returned, the client will send this new request
The handler must return a Future unsent so the client can further configure it and send it.
Parameters:
| Name | Type | Description |
|---|---|---|
handler |
function | the new redirect handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
- Type
- HttpClient
request(method, requestURI, responseHandler) → {HttpClientRequest}
Create an HTTP request to send to the server at the default host and port, specifying a response handler to receive
the response
Parameters:
| Name | Type | Description |
|---|---|---|
method |
Object | the HTTP method |
requestURI |
string | the relative URI |
responseHandler |
function | the response handler |
- Source:
Returns:
an HTTP client request object
- Type
- HttpClientRequest
requestAbs(method, serverAddress, absoluteURI, responseHandler) → {HttpClientRequest}
Like HttpClient#requestAbs using the
serverAddress parameter to connect to the
server instead of the absoluteURI parameter.
The request host header will still be created from the absoluteURI parameter.
Use to connect to a unix domain socket server.
Parameters:
| Name | Type | Description |
|---|---|---|
method |
Object | |
serverAddress |
SocketAddress | |
absoluteURI |
string | |
responseHandler |
function |
- Source:
Returns:
- Type
- HttpClientRequest
webSocket(options, handler)
Connect a WebSocket with the specified options.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Object | the request options |
handler |
function |
- Source:
webSocketAbs(url, headers, version, subProtocols, 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:
| Name | Type | Description |
|---|---|---|
url |
string | the absolute url |
headers |
MultiMap | the headers |
version |
Object | the websocket version |
subProtocols |
Array.<string> | the subprotocols to use |
handler |
function | handler that will be called if websocket connection fails |
- Source: