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> |
copy()
Copy this request
|
HttpRequest<T> |
followRedirects(boolean value)
Set wether or not to follow the directs for the request.
|
io.vertx.core.MultiMap |
headers() |
HttpRequest<T> |
host(String value)
Configure the request to use a new host
value . |
HttpRequest<T> |
method(io.vertx.core.http.HttpMethod value)
Configure the request to use a new method
value . |
HttpRequest<T> |
port(int value)
Configure the request to use a new port
value . |
HttpRequest<T> |
putHeader(String name,
String value)
Configure the request to add a new HTTP header.
|
io.vertx.core.MultiMap |
queryParams()
Return the current query parameters.
|
void |
send(io.vertx.core.Handler<io.vertx.core.AsyncResult<HttpResponse<T>>> handler)
Send a request, the
handler will receive the response as an HttpResponse . |
void |
sendBuffer(io.vertx.core.buffer.Buffer body,
io.vertx.core.Handler<io.vertx.core.AsyncResult<HttpResponse<T>>> handler)
Like
send(Handler) but with an HTTP request body buffer. |
void |
sendForm(io.vertx.core.MultiMap body,
io.vertx.core.Handler<io.vertx.core.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,
io.vertx.core.Handler<io.vertx.core.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(io.vertx.core.json.JsonObject body,
io.vertx.core.Handler<io.vertx.core.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 |
sendStream(io.vertx.core.streams.ReadStream<io.vertx.core.buffer.Buffer> body,
io.vertx.core.Handler<io.vertx.core.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> method(io.vertx.core.http.HttpMethod value)
value
.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> uri(String value)
value
.
When the uri has query parameters, they are set in the queryParams()
multimap, overwritting
any parameters previously set.
HttpRequest<T> putHeader(String name, String value)
name
- the header namevalue
- the header valueio.vertx.core.MultiMap headers()
HttpRequest<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 followedio.vertx.core.MultiMap queryParams()
HttpRequest<T> copy()
void sendStream(io.vertx.core.streams.ReadStream<io.vertx.core.buffer.Buffer> body, io.vertx.core.Handler<io.vertx.core.AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
stream.body
- the bodyvoid sendBuffer(io.vertx.core.buffer.Buffer body, io.vertx.core.Handler<io.vertx.core.AsyncResult<HttpResponse<T>>> handler)
send(Handler)
but with an HTTP request body
buffer.body
- the bodyvoid sendJsonObject(io.vertx.core.json.JsonObject body, io.vertx.core.Handler<io.vertx.core.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, io.vertx.core.Handler<io.vertx.core.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(io.vertx.core.MultiMap body, io.vertx.core.Handler<io.vertx.core.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 send(io.vertx.core.Handler<io.vertx.core.AsyncResult<HttpResponse<T>>> handler)
handler
will receive the response as an HttpResponse
.Copyright © 2017. All rights reserved.