Class HttpRequest<T>


  • public class HttpRequest<T>
    extends Object
    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(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

    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

    • an HttpResponse instance when the HTTP response has been received
    • a failure when the HTTP request failed (like a connection error) or when the HTTP response could not be obtained (like connection or unmarshalling errors)

    Most of the time, this client will buffer the HTTP response fully unless a specific is used such as .

    NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

    • Constructor Detail

      • HttpRequest

        public HttpRequest​(io.vertx.ext.web.client.HttpRequest delegate)
      • HttpRequest

        public HttpRequest​(Object delegate,
                           TypeArg<T> typeArg_0)
      • HttpRequest

        public HttpRequest​(io.vertx.ext.web.client.HttpRequest delegate,
                           TypeArg<T> typeArg_0)
    • Method Detail

      • getDelegate

        public io.vertx.ext.web.client.HttpRequest getDelegate()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • method

        public HttpRequest<T> method​(io.vertx.core.http.HttpMethod value)
        Parameters:
        value -
        Returns:
        a reference to this, so the API can be used fluently
      • port

        public HttpRequest<T> port​(int value)
        Parameters:
        value -
        Returns:
        a reference to this, so the API can be used fluently
      • as

        public <U> HttpRequest<U> as​(BodyCodec<U> responseCodec)
        Parameters:
        responseCodec - the response codec
        Returns:
        a reference to this, so the API can be used fluently
      • host

        public HttpRequest<T> host​(String value)
        Parameters:
        value -
        Returns:
        a reference to this, so the API can be used fluently
      • virtualHost

        public HttpRequest<T> virtualHost​(String value)
        Parameters:
        value -
        Returns:
        a reference to this, so the API can be used fluently
      • uri

        public HttpRequest<T> uri​(String value)
        Parameters:
        value -
        Returns:
        a reference to this, so the API can be used fluently
      • putHeaders

        public HttpRequest<T> putHeaders​(MultiMap headers)
        Parameters:
        headers - The HTTP headers
        Returns:
        a reference to this, so the API can be used fluently
      • putHeader

        public HttpRequest<T> putHeader​(String name,
                                        String value)
        Parameters:
        name - the header name
        value - the header value
        Returns:
        a reference to this, so the API can be used fluently
      • headers

        public MultiMap headers()
        Returns:
        The HTTP headers
      • basicAuthentication

        public HttpRequest<T> basicAuthentication​(String id,
                                                  String password)
        Parameters:
        id - the id
        password - the password
        Returns:
        a reference to this, so the API can be used fluently
      • basicAuthentication

        public HttpRequest<T> basicAuthentication​(Buffer id,
                                                  Buffer password)
        Parameters:
        id - the id
        password - the password
        Returns:
        a reference to this, so the API can be used fluently
      • bearerTokenAuthentication

        public HttpRequest<T> bearerTokenAuthentication​(String bearerToken)
        Parameters:
        bearerToken - the bearer token
        Returns:
        a reference to this, so the API can be used fluently
      • timeout

        public HttpRequest<T> timeout​(long value)
        Parameters:
        value - The quantity of time in milliseconds.
        Returns:
        a reference to this, so the API can be used fluently
      • addQueryParam

        public HttpRequest<T> addQueryParam​(String paramName,
                                            String paramValue)
        Parameters:
        paramName - the param name
        paramValue - the param value
        Returns:
        a reference to this, so the API can be used fluently
      • setQueryParam

        public HttpRequest<T> setQueryParam​(String paramName,
                                            String paramValue)
        Parameters:
        paramName - the param name
        paramValue - the param value
        Returns:
        a reference to this, so the API can be used fluently
      • followRedirects

        public HttpRequest<T> followRedirects​(boolean value)
        Parameters:
        value - true if redirections should be followed
        Returns:
        a reference to this, so the API can be used fluently
      • expect

        public HttpRequest<T> expect​(ResponsePredicate predicate)
        Parameters:
        predicate - the predicate
        Returns:
        a reference to this, so the API can be used fluently
      • queryParams

        public MultiMap queryParams()
        Returns:
        the current query parameters
      • copy

        public HttpRequest<T> copy()
        Returns:
        a copy of this request
      • multipartMixed

        public HttpRequest<T> multipartMixed​(boolean allow)
        Parameters:
        allow - true allows use of multipart mixed encoding
        Returns:
        a reference to this, so the API can be used fluently
      • sendStream

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendStream​(ReadStream<Buffer> body)
        Like send() but with an HTTP request body stream.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendStreamAndAwait

        public HttpResponse<T> sendStreamAndAwait​(ReadStream<Buffer> body)
        Blocking variant of io.vertx.mutiny.ext.web.client.HttpRequest#sendStream(io.vertx.mutiny.core.streams.ReadStream).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • sendStreamAndForget

        public void sendStreamAndForget​(ReadStream<Buffer> body)
        Variant of io.vertx.mutiny.ext.web.client.HttpRequest#sendStream(io.vertx.mutiny.core.streams.ReadStream) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.ext.web.client.HttpRequest#sendStream(io.vertx.mutiny.core.streams.ReadStream), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.ext.web.client.HttpRequest#sendStream(io.vertx.mutiny.core.streams.ReadStream) but you don't need to compose it with other operations.

        Parameters:
        body - the body
      • sendStream

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendStream​(org.reactivestreams.Publisher<Buffer> body)
        Like send() but with an HTTP request body stream.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendStreamAndAwait

        public HttpResponse<T> sendStreamAndAwait​(org.reactivestreams.Publisher<Buffer> body)
        Blocking variant of sendStream(Publisher<Buffer>).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • sendStreamAndForget

        public void sendStreamAndForget​(org.reactivestreams.Publisher<Buffer> body)
        Variant of sendStream(Publisher<Buffer>) that ignores the result of the operation.

        This method subscribes on the result of sendStream(Publisher<Buffer>), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendStream(Publisher<Buffer>) but you don't need to compose it with other operations.

        Parameters:
        body - the body
      • sendBuffer

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendBuffer​(Buffer body)
        Like send() but with an HTTP request body buffer.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendBufferAndAwait

        public HttpResponse<T> sendBufferAndAwait​(Buffer body)
        Blocking variant of sendBuffer(io.vertx.mutiny.core.buffer.Buffer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • sendJsonObject

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendJsonObject​(io.vertx.core.json.JsonObject body)
        Like send() but with an HTTP request body object encoded as json and the content type set to application/json.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendJsonObjectAndAwait

        public HttpResponse<T> sendJsonObjectAndAwait​(io.vertx.core.json.JsonObject body)
        Blocking variant of sendJsonObject(JsonObject).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • sendJsonObjectAndForget

        public void sendJsonObjectAndForget​(io.vertx.core.json.JsonObject body)
        Variant of sendJsonObject(JsonObject) that ignores the result of the operation.

        This method subscribes on the result of sendJsonObject(JsonObject), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendJsonObject(JsonObject) but you don't need to compose it with other operations.

        Parameters:
        body - the body
      • sendJson

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendJson​(Object body)
        Like send() but with an HTTP request body object encoded as json and the content type set to application/json.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendJsonAndAwait

        public HttpResponse<T> sendJsonAndAwait​(Object body)
        Blocking variant of sendJson(Object).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • sendJsonAndForget

        public void sendJsonAndForget​(Object body)
        Variant of sendJson(Object) that ignores the result of the operation.

        This method subscribes on the result of sendJson(Object), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendJson(Object) but you don't need to compose it with other operations.

        Parameters:
        body - the body
      • sendForm

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendForm​(MultiMap body)
        Like send() 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.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendFormAndAwait

        public HttpResponse<T> sendFormAndAwait​(MultiMap body)
        Blocking variant of sendForm(io.vertx.mutiny.core.MultiMap).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • sendForm

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendForm​(MultiMap body,
                                                                String charset)
        Like send() 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. NOTE: the use of this method is strongly discouraged to use when the form is a application/x-www-form-urlencoded encoded form since the charset to use must be UTF-8.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        charset -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendFormAndAwait

        public HttpResponse<T> sendFormAndAwait​(MultiMap body,
                                                String charset)
        Blocking variant of sendForm(io.vertx.mutiny.core.MultiMap,String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        charset -
        Returns:
        the HttpResponse instance produced by the operation.
      • sendMultipartForm

        public io.smallrye.mutiny.Uni<HttpResponse<T>> sendMultipartForm​(MultipartForm body)
        Like send() 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.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        body - the body
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendMultipartFormAndAwait

        public HttpResponse<T> sendMultipartFormAndAwait​(MultipartForm body)
        Blocking variant of sendMultipartForm(io.vertx.mutiny.ext.web.multipart.MultipartForm).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        body - the body
        Returns:
        the HttpResponse instance produced by the operation.
      • send

        public io.smallrye.mutiny.Uni<HttpResponse<T>> send()
        Send a request, the handler will receive the response as an HttpResponse.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendAndAwait

        public HttpResponse<T> sendAndAwait()
        Blocking variant of send().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the HttpResponse instance produced by the operation.
      • sendAndForget

        public void sendAndForget()
        Variant of send() that ignores the result of the operation.

        This method subscribes on the result of send(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from send() but you don't need to compose it with other operations.

      • putHeader

        public HttpRequest<T> putHeader​(String name,
                                        Iterable<String> value)
        Parameters:
        name - the header name
        value - the header value
        Returns:
        a reference to this, so the API can be used fluently
      • authentication

        public HttpRequest<T> authentication​(io.vertx.ext.auth.authentication.Credentials credentials)
        Parameters:
        credentials - the credentials to use.
        Returns:
        a reference to this, so the API can be used fluently
      • newInstance

        public static <T> HttpRequest<T> newInstance​(io.vertx.ext.web.client.HttpRequest arg)
      • newInstance

        public static <T> HttpRequest<T> newInstance​(io.vertx.ext.web.client.HttpRequest arg,
                                                     TypeArg<T> __typeArg_T)