Interface RequestBodyBuilder


  • public interface RequestBodyBuilder

    A builder interface for defining the body of a request.

    This interface provides several methods for defining a request body with different content. It is used for both regular request bodies and the bodies of the parts of a multipart request. An implementation is passed to a consumer which then invokes the desired method to set the body. Note that the methods are mutually exclusive; a concrete builder instance will allow only a single method call.

    • Method Detail

      • string

        void string​(String body,
                    String mediaType)
        Sets the request body as a string. Based on the media type, the content header is set.
        Parameters:
        body - the request body as string
        mediaType - the media type of the content
      • file

        void file​(Path path,
                  String mediaType)
        Sets the request body as a file. This can be used to upload files to a server. Based on the media type, the content header is set.
        Parameters:
        path - the path to the file to be uploaded
        mediaType - the media type of the content
      • json

        void json​(Object payload)
        Sets the request body as an object that is serialized to JSON. This method uses an internal JSON object mapper to generate a JSON representation from the object passed in. It also automatically sets a correct Content-Type header.
        Parameters:
        payload - the object to be used as request payload