vertx / io.vertx.ext.web.client / HttpRequest

HttpRequest

interface HttpRequest<T : Any>

A client-side HTTP request.

Instances are created by an WebClient instance, via one of the methods corresponding to the specific HTTP methods such as WebClient#get, 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

can be called. The 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

Most of the time, this client will buffer the HTTP response fully unless a specific BodyCodec is used such as BodyCodec#create(Handler).

Parameters

- the type of response body

Author
Julien Viet

Functions

addQueryParam

abstract fun addQueryParam(paramName: String, paramValue: String): HttpRequest<T>

Add a query parameter to the request.

as

abstract fun <U : Any> as(responseCodec: BodyCodec<U>): HttpRequest<U>

Configure the request to decode the response with the responseCodec.

copy

abstract fun copy(): HttpRequest<T>

Copy this request

followRedirects

abstract fun followRedirects(value: Boolean): HttpRequest<T>

Set wether or not to follow the directs for the request.

headers

abstract fun headers(): MultiMap

host

abstract fun host(value: String): HttpRequest<T>

Configure the request to use a new host value.

method

abstract fun method(value: HttpMethod): HttpRequest<T>

Configure the request to use a new method value.

port

abstract fun port(value: Int): HttpRequest<T>

Configure the request to use a new port value.

putHeader

abstract fun putHeader(name: String, value: String): HttpRequest<T>

Configure the request to add a new HTTP header.

queryParams

abstract fun queryParams(): MultiMap

Return the current query parameters.

send

abstract fun send(handler: Handler<AsyncResult<HttpResponse<T>>>): Unit

Send a request, the handler will receive the response as an HttpResponse.

sendBuffer

abstract fun sendBuffer(body: Buffer, handler: Handler<AsyncResult<HttpResponse<T>>>): Unit

Like #send(Handler) but with an HTTP request body buffer.

sendForm

abstract fun sendForm(body: MultiMap, handler: Handler<AsyncResult<HttpResponse<T>>>): Unit

Like #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.

sendJson

abstract fun sendJson(body: Any, handler: Handler<AsyncResult<HttpResponse<T>>>): Unit

Like #send(Handler) but with an HTTP request body object encoded as json and the content type set to application/json.

sendJsonObject

abstract fun sendJsonObject(body: JsonObject, handler: Handler<AsyncResult<HttpResponse<T>>>): Unit

Like #send(Handler) but with an HTTP request body object encoded as json and the content type set to application/json.

sendStream

abstract fun sendStream(body: ReadStream<Buffer>, handler: Handler<AsyncResult<HttpResponse<T>>>): Unit

Like #send(Handler) but with an HTTP request body stream.

setQueryParam

abstract fun setQueryParam(paramName: String, paramValue: String): HttpRequest<T>

Set a query parameter to the request.

ssl

abstract fun ssl(value: Boolean): HttpRequest<T>

timeout

abstract fun timeout(value: Long): HttpRequest<T>

Configures the amount of time in milliseconds after which if the request does not return any data within the timeout period an java.util.concurrent.TimeoutException fails the request.

Setting zero or a negative value disables the timeout.

uri

abstract fun uri(value: String): HttpRequest<T>

Configure the request to use a new request URI value.

When the uri has query parameters, they are set in the #queryParams() multimap, overwritting any parameters previously set.

virtualHost

abstract fun virtualHost(value: String): HttpRequest<T>

Configure the request to use a virtual host 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.