Class HttpRequest.Builder

java.lang.Object
com.luciad.net.http.HttpRequest.Builder
All Implemented Interfaces:
AutoCloseable
Enclosing class:
HttpRequest

public static final class HttpRequest.Builder extends Object implements AutoCloseable
A builder of HttpRequests.

Instances of HttpRequest.Builder are created by calling HttpRequest#newBuilder.

The builder can be used to configure the request URI, the request method (default is GET unless explicitly set), specific request headers, etc. The build method returns a new HttpRequest each time it is invoked. Once built an HttpRequest is immutable.

Since:
2023.0
  • Constructor Details Link icon

  • Method Details Link icon

    • finalize Link icon

      protected void finalize()
      Overrides:
      finalize in class Object
    • close Link icon

      public void close()
      Specified by:
      close in interface AutoCloseable
    • build Link icon

      @NotNull public HttpRequest build() throws IllegalStateException
      Returns an HttpRequest, based on the properties set on this builder.
      Returns:
      an HttpRequest, based on the properties set on this builder.
      Throws:
      IllegalStateException - if a URI has not been set.
    • uri Link icon

      @NotNull public HttpRequest.Builder uri(@NotNull String uri)
      Sets this HttpRequest's request URI.

      The provided URI can have a query string. This parameter is mandatory. If it is not set, HttpRequest.Builder#build will throw an exception.

      Parameters:
      uri - request URI string.
      Returns:
      this builder.
    • method Link icon

      @NotNull public HttpRequest.Builder method(@NotNull HttpRequestMethod method)
      Sets the request method of this builder.

      This parameter is optional. If not set, default is GET.

      Parameters:
      method - the method to use.
      Returns:
      this builder.
    • body Link icon

      @NotNull public HttpRequest.Builder body(@NotNull DataEntity body)
      Sets the HTTP request content.

      This parameter is optional unless this HttpRequest's method has been set to POST or PUT. If not set when the request method is POST or PUT, HttpRequest.Builder#build will throw an exception.

      Parameters:
      body - the request content.
      Returns:
      this builder.
    • header Link icon

      @NotNull public HttpRequest.Builder header(@NotNull String name, @NotNull String value)
      Sets the given name value pair to the set of headers for this request.
      Parameters:
      name - header name
      value - header value
      Returns:
      this builder.
    • header Link icon

      @NotNull public HttpRequest.Builder header(@NotNull HttpHeader header)
      Sets the given http header to the set of headers for this request.
      Parameters:
      header - an HttpHeader.
      Returns:
      this builder.
    • queryParameter Link icon

      @NotNull public HttpRequest.Builder queryParameter(@NotNull String name, @NotNull String value)
      Sets the given name value pair to the set of query parameters for this request.
      Parameters:
      name - query parameter name.
      value - query parameter value.
      Returns:
      this builder.
    • queryParameter Link icon

      @NotNull public HttpRequest.Builder queryParameter(@NotNull UriQueryParameter queryParameter)
      Sets the given query parameter to the set of query parameters for this request.
      Parameters:
      queryParameter - an UriQueryParameter.
      Returns:
      this builder.