public static final class HttpRequest.Builder extends Object implements AutoCloseable
HttpRequest
s.
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.
Constructor and Description |
---|
Builder(HttpRequest.Builder other) |
Modifier and Type | Method and Description |
---|---|
HttpRequest.Builder |
body(DataEntity body)
Sets the HTTP request content.
|
HttpRequest |
build()
Returns an
HttpRequest , based on the properties set on this builder. |
void |
close() |
protected void |
finalize() |
HttpRequest.Builder |
header(HttpHeader header)
Sets the given http header to the set of headers for this request.
|
HttpRequest.Builder |
header(String name,
String value)
Sets the given name value pair to the set of headers for this request.
|
HttpRequest.Builder |
method(HttpRequestMethod method)
Sets the request method of this builder.
|
HttpRequest.Builder |
queryParameter(String name,
String value)
Sets the given name value pair to the set of query parameters for this request.
|
HttpRequest.Builder |
queryParameter(UriQueryParameter queryParameter)
Sets the given query parameter to the set of query parameters for this request.
|
HttpRequest.Builder |
uri(String uri)
Sets this
HttpRequest 's request URI. |
public Builder(@NotNull HttpRequest.Builder other)
public void close()
close
in interface AutoCloseable
@NotNull public HttpRequest build() throws IllegalStateException
HttpRequest
, based on the properties set on this builder.HttpRequest
, based on the properties set on this builder.IllegalStateException
- if a URI has not been set.@NotNull public HttpRequest.Builder uri(@NotNull String uri)
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.
uri
- request URI string.@NotNull public HttpRequest.Builder method(@NotNull HttpRequestMethod method)
This parameter is optional. If not set, default is GET.
method
- the method to use.@NotNull public HttpRequest.Builder body(@NotNull DataEntity body)
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.
body
- the request content.@NotNull public HttpRequest.Builder header(@NotNull String name, @NotNull String value)
name
- header namevalue
- header value@NotNull public HttpRequest.Builder header(@NotNull HttpHeader header)
header
- an HttpHeader
.@NotNull public HttpRequest.Builder queryParameter(@NotNull String name, @NotNull String value)
name
- query parameter name.value
- query parameter value.@NotNull public HttpRequest.Builder queryParameter(@NotNull UriQueryParameter queryParameter)
queryParameter
- an UriQueryParameter
.