Module bus.http
Package org.miaixz.bus.http.plugin.httpz
Class RequestBuilder<T extends RequestBuilder>
java.lang.Object
org.miaixz.bus.http.plugin.httpz.RequestBuilder<T>
- Type Parameters:
T- The type of the concrete builder implementation, for method chaining.
- Direct Known Subclasses:
DeleteBuilder,GetBuilder,HeadBuilder,PostBuilder,PutBuilder
An abstract base builder for creating HTTP requests. It provides a fluent API for setting common request properties
like URL, headers, parameters, and tags.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionA map of pre-encoded request parameters.A map of request headers.protected HttpdThe HTTP client instance.protected StringA unique identifier for the request.A map of request parameters (e.g., query string or form data).protected ObjectAn optional tag for the request, used for cancellation.protected StringThe URL for the request. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEncoded(String key, String val) Adds a single pre-encoded parameter to the request.addEncoded(Map<String, String> params) Replaces all existing pre-encoded parameters with the given map.Adds a single header to the request.Replaces all existing headers with the given map of headers.Adds all properties of a Plain Old Java Object (POJO) as parameters.Adds a single parameter to the request.Replaces all existing parameters with the given map of parameters.abstract RequestCallbuild()Abstract method to be implemented by subclasses to build the final, executable request call.Sets the unique identifier for this request.Sets the tag for this request, which can be used to cancel it later.Sets the URL for this request.
-
Field Details
-
httpd
The HTTP client instance. -
id
A unique identifier for the request. -
url
The URL for the request. -
tag
An optional tag for the request, used for cancellation. -
headers
A map of request headers. -
params
A map of request parameters (e.g., query string or form data). -
encoded
A map of pre-encoded request parameters.
-
-
Constructor Details
-
RequestBuilder
Constructs a new RequestBuilder.- Parameters:
httpd- TheHttpdclient instance.
-
-
Method Details
-
id
Sets the unique identifier for this request.- Parameters:
id- The request ID.- Returns:
- This builder instance for chaining.
-
url
Sets the URL for this request.- Parameters:
url- The request URL.- Returns:
- This builder instance for chaining.
-
tag
Sets the tag for this request, which can be used to cancel it later.- Parameters:
tag- The request tag.- Returns:
- This builder instance for chaining.
-
addHeader
Replaces all existing headers with the given map of headers.- Parameters:
headers- A map of headers to set.- Returns:
- This builder instance for chaining.
-
addHeader
Adds a single header to the request.- Parameters:
key- The header name.val- The header value.- Returns:
- This builder instance for chaining.
-
addParam
Replaces all existing parameters with the given map of parameters.- Parameters:
params- A map of parameters to set.- Returns:
- This builder instance for chaining.
-
addParam
Adds a single parameter to the request.- Parameters:
key- The parameter name.val- The parameter value.- Returns:
- This builder instance for chaining.
-
addParam
Adds all properties of a Plain Old Java Object (POJO) as parameters.- Parameters:
object- The object whose properties will be added as parameters.- Returns:
- This builder instance for chaining.
-
addEncoded
Replaces all existing pre-encoded parameters with the given map.- Parameters:
params- A map of pre-encoded parameters to set.- Returns:
- This builder instance for chaining.
-
addEncoded
Adds a single pre-encoded parameter to the request.- Parameters:
key- The pre-encoded parameter name.val- The pre-encoded parameter value.- Returns:
- This builder instance for chaining.
-
build
Abstract method to be implemented by subclasses to build the final, executable request call.- Returns:
- The constructed
RequestCall.
-