public class HttpClient extends Object implements NettyConnector<HttpClientResponse,HttpClientRequest>
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpClient.Builder |
| Modifier and Type | Field and Description |
|---|---|
static String |
USER_AGENT |
| Modifier and Type | Method and Description |
|---|---|
static HttpClient.Builder |
builder()
Creates a builder for
HttpClient |
static HttpClient |
create()
Creates a simple HTTP Client with no address to which this client should connect
and with default sslContext support.
|
static HttpClient |
create(java.util.function.Consumer<? super HttpClientOptions.Builder> options)
Creates a simple HTTP client using provided
options |
static HttpClient |
create(int port)
Creates a simple HTTP client bound on localhost and the provided port
|
static HttpClient |
create(String address)
Creates a simple HTTP client bound on the provided address and port 80
|
static HttpClient |
create(String address,
int port)
Creates a simple HTTP client bound on the provided address and port
|
Mono<HttpClientResponse> |
delete(String url)
HTTP DELETE the passed URL.
|
Mono<HttpClientResponse> |
delete(String url,
java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
HTTP DELETE the passed URL.
|
Mono<HttpClientResponse> |
get(String url)
HTTP GET the passed URL.
|
Mono<HttpClientResponse> |
get(String url,
java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
HTTP GET the passed URL.
|
Mono<HttpClientResponse> |
newHandler(java.util.function.BiFunction<? super HttpClientResponse,? super HttpClientRequest,? extends Publisher<Void>> ioHandler)
Prepare a
BiFunction IO handler that will react on a new connected state
each
time
the returned Mono is subscribed. |
HttpClientOptions |
options()
Get a copy of the
HttpClientOptions currently in effect. |
Mono<HttpClientResponse> |
patch(String url)
HTTP PATCH the passed URL.
|
Mono<HttpClientResponse> |
patch(String url,
java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
HTTP PATCH the passed URL.
|
Mono<HttpClientResponse> |
post(String url,
java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
HTTP POST the passed URL.
|
Mono<HttpClientResponse> |
put(String url,
java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
HTTP PUT the passed URL.
|
Mono<HttpClientResponse> |
request(HttpMethod method,
String url,
java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
Use the passed HTTP method to send to the given URL.
|
String |
toString() |
Mono<HttpClientResponse> |
ws(String url)
WebSocket to the passed URL.
|
Mono<HttpClientResponse> |
ws(String url,
java.util.function.Consumer<? super HttpHeaders> headerBuilder)
WebSocket to the passed URL.
|
Mono<HttpClientResponse> |
ws(String url,
java.util.function.Consumer<? super HttpHeaders> headerBuilder,
String subprotocols)
WebSocket to the passed URL, negotiating one of the passed subprotocols.
|
Mono<HttpClientResponse> |
ws(String url,
String subprotocols)
WebSocket to the passed URL, negotiating one of the passed subprotocols.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitstart, start, startAndAwait, startAndAwaitpublic static final String USER_AGENT
public static HttpClient create()
public static HttpClient create(java.util.function.Consumer<? super HttpClientOptions.Builder> options)
optionsoptions - the options for the client, including the address to which this
client should connectoptionspublic static HttpClient create(String address)
address - the host to which this client should connect.public static HttpClient create(String address, int port)
address - the host to which this client should connect.port - the port to which this client should connect.public static HttpClient create(int port)
port - the port to which this client should connect.public static HttpClient.Builder builder()
HttpClientpublic final Mono<HttpClientResponse> delete(String url, java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
url - the target remote URLhandler - the Function to invoke on open channelMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> delete(String url)
url - the target remote URLMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> get(String url, java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
url - the target remote URLhandler - the Function to invoke on open channelMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> get(String url)
url - the target remote URLMono of the HttpServerResponse ready to consume for
responsepublic Mono<HttpClientResponse> newHandler(java.util.function.BiFunction<? super HttpClientResponse,? super HttpClientRequest,? extends Publisher<Void>> ioHandler)
NettyConnectorBiFunction IO handler that will react on a new connected state
each
time
the returned Mono is subscribed. This NettyConnector shouldn't assume
any state related to the individual created/cleaned resources.
The IO handler will return Publisher to signal when to terminate the
underlying resource channel.
newHandler in interface NettyConnector<HttpClientResponse,HttpClientRequest>ioHandler - the in/out callback returning a closing publisherMono completing with a Disposable token to dispose
the active handler (server, client connection...) or failing with the connection
error.public final Mono<HttpClientResponse> patch(String url, java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
url - the target remote URLhandler - the Function to invoke on open channelMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> patch(String url)
url - the target remote URLMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> post(String url, java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
url - the target remote URLhandler - the Function to invoke on open channelMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> put(String url, java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
url - the target remote URLhandler - the Function to invoke on open channelMono of the HttpServerResponse ready to consume for
responsepublic Mono<HttpClientResponse> request(HttpMethod method, String url, java.util.function.Function<? super HttpClientRequest,? extends Publisher<Void>> handler)
method - the HTTP method to sendurl - the target remote URLhandler - the Function to invoke on opened TCP connectionMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> ws(String url)
url - the target remote URLMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> ws(String url, java.util.function.Consumer<? super HttpHeaders> headerBuilder)
url - the target remote URLheaderBuilder - the header Consumer to invoke before sending websocket
handshakeMono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> ws(String url, String subprotocols)
The negotiated subprotocol can be accessed through the HttpClientResponse
by switching to websocket (using any of the receiveWebSocket
methods) and using WebsocketInbound.selectedSubprotocol().
To send data through the websocket, use HttpClientResponse.receiveWebsocket(BiFunction)
and then use the function's WebsocketOutbound.
url - the target remote URLsubprotocols - the subprotocol(s) to negotiate, comma-separated, or null if not relevant.Mono of the HttpServerResponse ready to consume for
responsepublic final Mono<HttpClientResponse> ws(String url, java.util.function.Consumer<? super HttpHeaders> headerBuilder, String subprotocols)
The negotiated subprotocol can be accessed through the HttpClientResponse
by switching to websocket (using any of the receiveWebSocket
methods) and using WebsocketInbound.selectedSubprotocol().
To send data through the websocket, use HttpClientResponse.receiveWebsocket(BiFunction)
and then use the function's WebsocketOutbound.
url - the target remote URLheaderBuilder - the header Consumer to invoke before sending websocket
handshakesubprotocols - the subprotocol(s) to negotiate, comma-separated, or null if not relevant.Mono of the HttpServerResponse ready to consume for
responsepublic HttpClientOptions options()
HttpClientOptions currently in effect.