Module bus.http

Class PutBuilder


public class PutBuilder extends RequestBuilder<PutBuilder>
A builder for creating HTTP PUT requests using a fluent interface. It supports setting URL, parameters, headers, a raw request body, and multipart file uploads.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • PutBuilder

      public PutBuilder(Httpd httpd)
      Constructs a new PutBuilder.
      Parameters:
      httpd - The Httpd client instance.
  • Method Details

    • build

      public RequestCall build()
      Description copied from class: RequestBuilder
      Abstract method to be implemented by subclasses to build the final, executable request call.
      Specified by:
      build in class RequestBuilder<PutBuilder>
      Returns:
      The constructed RequestCall.
    • body

      public PutBuilder body(String body)
      Sets a raw string as the request body. This is typically used for sending content like JSON or XML. The 'Content-Type' header should be set accordingly.
      Parameters:
      body - The raw string content for the request body.
      Returns:
      This builder instance for chaining.
    • multipartBody

      public PutBuilder multipartBody(MultipartBody multipartBody)
      Sets a pre-constructed MultipartBody. This allows for advanced multipart request configuration.
      Parameters:
      multipartBody - The pre-built multipart body.
      Returns:
      This builder instance for chaining.
    • addFile

      public PutBuilder addFile(String partName, String fileName, byte[] content)
      Adds a file to the multipart request from a byte array.
      Parameters:
      partName - The name of the form field.
      fileName - The name of the file.
      content - The file content as a byte array.
      Returns:
      This builder instance for chaining.
    • addFile

      public PutBuilder addFile(String partName, String fileName, File file)
      Adds a file to the multipart request from a File object.
      Parameters:
      partName - The name of the form field.
      fileName - The name of the file.
      file - The file to be uploaded.
      Returns:
      This builder instance for chaining.
    • addFile

      public PutBuilder addFile(String partName, String fileName, String content) throws UnsupportedEncodingException
      Adds a file to the multipart request from a string, using the default UTF-8 encoding.
      Parameters:
      partName - The name of the form field.
      fileName - The name of the file.
      content - The string content of the file.
      Returns:
      This builder instance for chaining.
      Throws:
      UnsupportedEncodingException - if UTF-8 is not supported.
    • addFile

      public PutBuilder addFile(String partName, String fileName, String content, String charsetName) throws UnsupportedEncodingException
      Adds a file to the multipart request from a string with a specified charset.
      Parameters:
      partName - The name of the form field.
      fileName - The name of the file.
      content - The string content of the file.
      charsetName - The name of the charset to use for encoding.
      Returns:
      This builder instance for chaining.
      Throws:
      UnsupportedEncodingException - if the specified charset is not supported.
    • addFile

      public PutBuilder addFile(String partName, String fileName, byte[] content, String charsetName)
      Parameters:
      partName - The name of the form field.
      fileName - The name of the file.
      content - The file content as a byte array.
      charsetName - This parameter is ignored.
      Returns:
      This builder instance for chaining.