Interface RequestBuilder


  • public interface RequestBuilder

    An interface that allows the definition of HTTP requests to be executed.

    This interface provides methods to set the single properties of an HTTP request. This can be done in a convenient way using method chaining. A client only has to set the properties that are relevant for a specific request; as a minimum, the request URI must be set. Note that there is no build() method to conclude the definition of the request; this is not necessary as the HTTP client can figure out itself when to collect the properties that have been defined.

    • Method Detail

      • method

        RequestBuilder method​(RequestBuilder.Method method)
        Sets the HTTP method to be used for the request. If no method is set explicitly, the default is GET.
        Parameters:
        method - the HTTP method for the request
        Returns:
        this request builder
      • uri

        RequestBuilder uri​(String uri)
        Set the URI for the request.
        Parameters:
        uri - the request URI
        Returns:
        this request builder
      • header

        RequestBuilder header​(String name,
                              String value)
        Sets a request header.
        Parameters:
        name - the header name
        value - the header value
        Returns:
        this request builder
      • body

        RequestBuilder body​(Consumer<RequestBodyBuilder> bodyProducer)
        Adds a request body to this builder. The consumer passed to this method is invoked with a RequestBodyBuilder which can be used to define the request body. Use this method to define request bodies for simple requests; for multi-part requests, multiPart(String, Consumer) has to be used instead.
        Parameters:
        bodyProducer - the producer for the request body
        Returns:
        this request builder
      • multiPart

        RequestBuilder multiPart​(String name,
                                 Consumer<RequestBodyBuilder> partProducer)
        Adds a part of a multi-part request to this builder. When using this method, a multi-part request is generated. It has to be called for each part. The single parts are defined via consumer objects that are passed RequestPartBuilder instances for the definition of the parts.
        Parameters:
        name - the name of the part
        partProducer - the producer for the request part
        Returns:
        this request builder