Interface HttpClientRequest


  • public interface HttpClientRequest
    Http request that is built and sent to the server.

    Largely wraps the standard JDK HttpRequest with additional support for converting beans to body content and converting beans from response content.

    
    
      HelloDto dto = clientContext.request()
           .path("hello").queryParam("name", "Rob").queryParam("say", "Whats up")
           .GET()
           .bean(HelloDto.class);
    
     
    See Also:
    HttpClientContext
    • Method Detail

      • suppressLogging

        HttpClientRequest suppressLogging()
        For this request suppress payload logging.

        The payload contains sensitive content and the request and response content should be suppressed and not included in request logging.

      • label

        HttpClientRequest label​(String label)
        Set a label for the request. The label is intended to be used to group and identify metrics for the request.
        Parameters:
        label - The label that can be used to identify metrics for the request
      • getAttribute

        <E> E getAttribute​(String key)
        Return a custom attribute typically set by a RequestIntercept.beforeRequest(HttpClientRequest).
        Type Parameters:
        E - The inferred type of the attribute
        Parameters:
        key - The key for the custom attribute
        Returns:
        The custom attribute
      • requestTimeout

        HttpClientRequest requestTimeout​(Duration requestTimeout)
        Set the request timeout to use for this request. When not set the default request timeout will be used.
        Parameters:
        requestTimeout - The request timeout to use for this request.
        Returns:
        The request being built
      • headerAddIfAbsent

        HttpClientRequest headerAddIfAbsent​(String name,
                                            Object value)
        Add the header to the request but only if there is no existing value for the given header.
        Parameters:
        name - The header name
        value - The header value
        Returns:
        The request being built
      • header

        HttpClientRequest header​(String name,
                                 String value)
        Add the header to the request.
        Parameters:
        name - The header name
        value - The header value
        Returns:
        The request being built
      • header

        HttpClientRequest header​(String name,
                                 Object value)
        Add the header to the request implicitly converting the value to a String.
        Parameters:
        name - The header name
        value - The header value
        Returns:
        The request being built
      • header

        HttpClientRequest header​(Map<String,​?> headers)
        Add the headers to the request via map.
        Parameters:
        headers - The headers as name value map to add
        Returns:
        The request being built
      • header

        List<String> header​(String name)
        Return the header values that have been set for the given header name.
        Returns:
        The headers values or an empty collection if the header has not been specified yet.
      • gzip

        HttpClientRequest gzip​(boolean gzip)
        Set if body content should be gzip encoded.
        Parameters:
        gzip - Set true to gzip encode the body content.
        Returns:
        The request being built
      • url

        HttpClientRequest url​(String url)
        Set the URL to use replacing the base URL.
        {code
        
          HttpResponse res = clientContext.request()
               .url("http://127.0.0.1:8887")
               .path("hello")
               .GET()
               .asString();
        
         }
        Parameters:
        url - The url effectively replacing the base url.
        Returns:
        The request being built
        See Also:
        HttpClientContext.Builder.baseUrl(String)
      • path

        HttpClientRequest path​(String path)
        Add a path segment to the URL.
        Parameters:
        path - The path segment to add to the URL path.
        Returns:
        The request being built
      • path

        HttpClientRequest path​(int val)
        Add a path segment to the URL.
        Parameters:
        val - The value to add to the URL path.
        Returns:
        The request being built
      • path

        HttpClientRequest path​(long val)
        Add a path segment to the URL.
        Parameters:
        val - The value to add to the URL path.
        Returns:
        The request being built
      • path

        HttpClientRequest path​(Object val)
        Add a path segment to the URL.
        Parameters:
        val - The value to add to the URL path.
        Returns:
        The request being built
      • matrixParam

        HttpClientRequest matrixParam​(String name,
                                      String value)
        Add a matrix parameter to the current path segment.
        Parameters:
        name - The matrix parameter name
        value - The matrix parameter value which can be null
        Returns:
        The request being built
      • matrixParam

        HttpClientRequest matrixParam​(String name,
                                      Object value)
        Add a matrix parameter to the current path segment.
        Parameters:
        name - The matrix parameter name
        value - The matrix parameter value which can be null
        Returns:
        The request being built
      • queryParam

        HttpClientRequest queryParam​(String name,
                                     String value)
        Add a query parameter
        Parameters:
        name - The name of the query parameter
        value - The value of the query parameter which can be null
        Returns:
        The request being built
      • queryParam

        HttpClientRequest queryParam​(String name,
                                     Object value)
        Add a query parameter
        Parameters:
        name - The name of the query parameter
        value - The value of the query parameter which can be null
        Returns:
        The request being built
      • queryParam

        HttpClientRequest queryParam​(Map<String,​?> params)
        Add a multiple query parameters as name value map.
        Parameters:
        params - The query parameters
        Returns:
        The request being built
      • formParam

        HttpClientRequest formParam​(String name,
                                    String value)
        Add a form parameter.
        Parameters:
        name - The form parameter name
        value - The form parameter value which can be null
        Returns:
        The request being built
      • formParam

        HttpClientRequest formParam​(String name,
                                    Object value)
        Add a form parameter.
        Parameters:
        name - The form parameter name
        value - The form parameter value which can be null
        Returns:
        The request being built
      • formParam

        HttpClientRequest formParam​(Map<String,​?> params)
        Add the form parameters via a map.
        Parameters:
        params - The form parameters as name value map
        Returns:
        The request being built
      • body

        HttpClientRequest body​(Object bean)
        Set the body as a bean using the default content type. The default content type will often be application/json; charset=utf8.
      • body

        HttpClientRequest body​(String body)
        Set the body content as a string.
        Parameters:
        body - The body content
        Returns:
        The request being built
      • body

        HttpClientRequest body​(byte[] body)
        Set the body content as a bytes.
        Parameters:
        body - The body content
        Returns:
        The request being built
      • body

        HttpClientRequest body​(Supplier<? extends InputStream> supplier)
        Set the body content with supplied InputStream.
        Parameters:
        supplier - The supplier of InputStream content to send as body content
        Returns:
        The request being built
      • body

        HttpClientRequest body​(Path file)
        Set the body content with supplied InputStream.
        Parameters:
        file - The file to send as body content
        Returns:
        The request being built