T
- the type of response bodypublic interface HttpRequest<T>
Instances are created by an WebClient
instance, via one of the methods corresponding to the specific
HTTP methods such as WebClient.get(java.lang.String)
, etc...
The request shall be configured prior sending, the request is immutable and when a mutator method is called, a new request is returned allowing to expose the request in a public API and apply further customization.
After the request has been configured, the methods
send(Handler)
sendStream(ReadStream, Handler)
sendJson(Object, Handler)
()}sendForm(MultiMap, Handler)
sendXXX
methods perform the actual request, they can be called multiple times to perform the same HTTP
request at different points in time.
The handler is called back with
HttpResponse
instance when the HTTP response has been received
Most of the time, this client will buffer the HTTP response fully unless a specific BodyCodec
is used
such as BodyCodec.create(Handler)
.
Modifier and Type | Method and Description |
---|---|
HttpRequest<T> |
addQueryParam(String paramName,
String paramValue)
Add a query parameter to the request.
|
<U> HttpRequest<U> |
as(BodyCodec<U> responseCodec)
Configure the request to decode the response with the
responseCodec . |
HttpRequest<T> |
basicAuthentication(Buffer id,
Buffer password)
Configure the request to perform basic access authentication.
|
HttpRequest<T> |
basicAuthentication(String id,
String password)
Configure the request to perform basic access authentication.
|
HttpRequest<T> |
bearerTokenAuthentication(String bearerToken)
Configure the request to perform bearer token authentication.
|
HttpRequest<T> |
copy()
Copy this request
|
default HttpRequest<T> |
expect(java.util.function.Function<HttpResponse<Void>,ResponsePredicateResult> predicate)
Add an expectation that the response is valid according to the provided
predicate . |
HttpRequest<T> |
expect(ResponsePredicate predicate)
Add an expectation that the response is valid according to the provided
predicate . |
HttpRequest<T> |
followRedirects(boolean value)
Set wether or not to follow the directs for the request.
|
MultiMap |
headers() |
HttpRequest<T> |
host(String value)
Configure the request to use a new host
value . |
HttpRequest<T> |
method(HttpMethod value)
Configure the request to use a new method
value . |
HttpRequest<T> |
multipartMixed(boolean allow)
Allow or disallow multipart mixed encoding when sending
MultipartForm having files sharing the same
file name. |
HttpRequest<T> |
port(int value)
Configure the request to use a new port
value . |
HttpRequest<T> |
putHeader(String name,
Iterable<String> value)
Configure the request to set a new HTTP header with multiple values.
|
HttpRequest<T> |
putHeader(String name,
String value)
Configure the request to set a new HTTP header.
|
HttpRequest<T> |
putHeaders(MultiMap headers)
Configure the request to add multiple HTTP headers .
|
MultiMap |
queryParams()
Return the current query parameters.
|
HttpRequest<T> |
rawMethod(String method)
Configure the request to use a custom HTTP method
|
void |
send(Handler<AsyncResult<HttpResponse<T>>> handler)
Send a request, the
handler will receive the response as an HttpResponse . |
void |
sendBuffer(Buffer body,
Handler<AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body buffer. |
void |
sendForm(MultiMap body,
Handler<AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body multimap encoded as form and the content type
set to application/x-www-form-urlencoded . |
void |
sendJson(Object body,
Handler<AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body object encoded as json and the content type
set to application/json . |
void |
sendJsonObject(JsonObject body,
Handler<AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body object encoded as json and the content type
set to application/json . |
void |
sendMultipartForm(MultipartForm body,
Handler<AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body multimap encoded as form and the content type
set to multipart/form-data . |
void |
sendStream(ReadStream<Buffer> body,
Handler<AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body stream. |
HttpRequest<T> |
setQueryParam(String paramName,
String paramValue)
Set a query parameter to the request.
|
HttpRequest<T> |
ssl(Boolean value) |
HttpRequest<T> |
timeout(long value)
Configures the amount of time in milliseconds after which if the request does not return any data within the timeout
period an
TimeoutException fails the request. |
HttpRequest<T> |
uri(String value)
Configure the request to use a new request URI
value . |
HttpRequest<T> |
virtualHost(String value)
Configure the request to use a virtual host
value . |
HttpRequest<T> method(HttpMethod value)
value
.HttpRequest<T> rawMethod(String method)
HttpRequest<T> port(int value)
value
.<U> HttpRequest<U> as(BodyCodec<U> responseCodec)
responseCodec
.responseCodec
- the response codecHttpRequest<T> host(String value)
value
.HttpRequest<T> virtualHost(String value)
value
.
Usually the header host (:authority pseudo header for HTTP/2) is set from the request host value
since this host value resolves to the server IP address.
Sometimes you need to set a host header for an address that does not resolve to the server IP address.
The virtual host value overrides the value of the actual host header (:authority pseudo header
for HTTP/2).
The virtual host is also be used for SNI.HttpRequest<T> uri(String value)
value
.
When the uri has query parameters, they are set in the queryParams()
multimap, overwritting
any parameters previously set.
HttpRequest<T> putHeaders(MultiMap headers)
headers
- The HTTP headersHttpRequest<T> putHeader(String name, String value)
name
- the header namevalue
- the header valueHttpRequest<T> putHeader(String name, Iterable<String> value)
name
- the header namevalue
- the header valueMultiMap headers()
HttpRequest<T> basicAuthentication(String id, String password)
In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic <credentials>', where credentials is the base64 encoding of id and password joined by a colon.
id
- the idpassword
- the passwordHttpRequest<T> basicAuthentication(Buffer id, Buffer password)
In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic <credentials>', where credentials is the base64 encoding of id and password joined by a colon.
id
- the idpassword
- the passwordHttpRequest<T> bearerTokenAuthentication(String bearerToken)
In OAuth 2.0, a request contains a header field of the form 'Authorization: Bearer <bearerToken>', where bearerToken is the bearer token issued by an authorization server to access protected resources.
bearerToken
- the bearer tokenHttpRequest<T> ssl(Boolean value)
HttpRequest<T> timeout(long value)
TimeoutException
fails the request.
Setting zero or a negative value
disables the timeout.
value
- The quantity of time in milliseconds.HttpRequest<T> addQueryParam(String paramName, String paramValue)
paramName
- the param nameparamValue
- the param valueHttpRequest<T> setQueryParam(String paramName, String paramValue)
paramName
- the param nameparamValue
- the param valueHttpRequest<T> followRedirects(boolean value)
value
- true if redirections should be followeddefault HttpRequest<T> expect(java.util.function.Function<HttpResponse<Void>,ResponsePredicateResult> predicate)
predicate
.
Multiple predicates can be added.
predicate
- the predicateHttpRequest<T> expect(ResponsePredicate predicate)
predicate
.
Multiple predicates can be added.
predicate
- the predicateMultiMap queryParams()
HttpRequest<T> copy()
HttpRequest<T> multipartMixed(boolean allow)
MultipartForm
having files sharing the same
file name.
true
.
false
if you want to achieve the behavior for HTML5.allow
- true
allows use of multipart mixed encodingvoid sendStream(ReadStream<Buffer> body, Handler<AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
stream.body
- the bodyvoid sendBuffer(Buffer body, Handler<AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
buffer.body
- the bodyvoid sendJsonObject(JsonObject body, Handler<AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
object encoded as json and the content type
set to application/json
.body
- the bodyvoid sendJson(Object body, Handler<AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
object encoded as json and the content type
set to application/json
.body
- the bodyvoid sendForm(MultiMap body, Handler<AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
multimap encoded as form and the content type
set to application/x-www-form-urlencoded
.
When the content type header is previously set to multipart/form-data
it will be used instead.
body
- the bodyvoid sendMultipartForm(MultipartForm body, Handler<AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
multimap encoded as form and the content type
set to multipart/form-data
. You may use this method to send attributes and upload files.body
- the bodyvoid send(Handler<AsyncResult<HttpResponse<T>>> handler)
handler
will receive the response as an HttpResponse
.Copyright © 2023 Eclipse. All rights reserved.