io.vertx.ext.web.client

## Interface HttpRequest<T>

- Type Parameters:
    `T` - the type of response body

      public interface HttpRequest<T>

  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

  - `send(Handler)`
  - `sendStream(ReadStream, Handler)`
  - `sendJson(Object, Handler)` ()}
  - `sendForm(MultiMap, Handler)`
  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 `BodyCodec` is used such as `BodyCodec.create(Handler)`.

  Author:
    Julien Viet

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    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
    `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>` | `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.
    `MultiMap` | `queryParams()` Return the current query parameters.
    `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`.

- - ### Method Detail

    - #### method

          HttpRequest<T> method(HttpMethod value)

      Configure the request to use a new method `value`.
      Returns:
        a reference to this, so the API can be used fluently

    - #### port

          HttpRequest<T> port(int value)

      Configure the request to use a new port `value`.
      Returns:
        a reference to this, so the API can be used fluently

    - #### as

          <U> HttpRequest<U> as(BodyCodec<U> responseCodec)

      Configure the request to decode the response with the `responseCodec`.
      Parameters:
        `responseCodec` - the response codec
      Returns:
        a reference to this, so the API can be used fluently

    - #### host

          HttpRequest<T> host(String value)

      Configure the request to use a new host `value`.
      Returns:
        a reference to this, so the API can be used fluently

    - #### virtualHost

          HttpRequest<T> virtualHost(String value)

      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.
      Returns:
        a reference to this, so the API can be used fluently

    - #### uri

          HttpRequest<T> uri(String value)

      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.

      Returns:
        a reference to this, so the API can be used fluently

    - #### putHeader

          HttpRequest<T> putHeader(String name,
                                   String value)

      Configure the request to add a new HTTP header.
      Parameters:
        `name` - the header name
        `value` - the header value
      Returns:
        a reference to this, so the API can be used fluently

    - #### headers

          MultiMap headers()

      Returns:
        The HTTP headers

    - #### ssl

          HttpRequest<T> ssl(boolean value)

    - #### timeout

          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.

      Setting zero or a negative `value` disables the timeout.

      Parameters:
        `value` - The quantity of time in milliseconds.
      Returns:
        a reference to this, so the API can be used fluently

    - #### addQueryParam

          HttpRequest<T> addQueryParam(String paramName,
                                       String paramValue)

      Add a query parameter to the request.
      Parameters:
        `paramName` - the param name
        `paramValue` - the param value
      Returns:
        a reference to this, so the API can be used fluently

    - #### setQueryParam

          HttpRequest<T> setQueryParam(String paramName,
                                       String paramValue)

      Set a query parameter to the request.
      Parameters:
        `paramName` - the param name
        `paramValue` - the param value
      Returns:
        a reference to this, so the API can be used fluently

    - #### followRedirects

          HttpRequest<T> followRedirects(boolean value)

      Set wether or not to follow the directs for the request.
      Parameters:
        `value` - true if redirections should be followed
      Returns:
        a reference to this, so the API can be used fluently

    - #### expect

          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`.

      Multiple predicates can be added.

      Parameters:
        `predicate` - the predicate
      Returns:
        a reference to this, so the API can be used fluently

    - #### expect

          HttpRequest<T> expect(ResponsePredicate predicate)

      Add an expectation that the response is valid according to the provided `predicate`.

      Multiple predicates can be added.

      Parameters:
        `predicate` - the predicate
      Returns:
        a reference to this, so the API can be used fluently

    - #### queryParams

          MultiMap queryParams()

      Return the current query parameters.
      Returns:
        the current query parameters

    - #### copy

          HttpRequest<T> copy()

      Copy this request
      Returns:
        a copy of this request

    - #### sendStream

          void sendStream(ReadStream<Buffer> body,
                          Handler<AsyncResult<HttpResponse<T>>> handler)

      Like `send(Handler)` but with an HTTP request `body` stream.
      Parameters:
        `body` - the body

    - #### sendBuffer

          void sendBuffer(Buffer body,
                          Handler<AsyncResult<HttpResponse<T>>> handler)

      Like `send(Handler)` but with an HTTP request `body` buffer.
      Parameters:
        `body` - the body

    - #### sendJsonObject

          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`.
      Parameters:
        `body` - the body

    - #### sendJson

          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`.
      Parameters:
        `body` - the body

    - #### sendForm

          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`.

      When the content type header is previously set to `multipart/form-data` it will be used instead.

      Parameters:
        `body` - the body

    - #### sendMultipartForm

          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`. You may use this method to send attributes and upload files.
      Parameters:
        `body` - the body

    - #### send

          void send(Handler<AsyncResult<HttpResponse<T>>> handler)

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

Copyright © 2018 Eclipse. All rights reserved.