public class RestRequestBuilder extends Object
HttpRequests. Handles ignoring null queryParams and Headers by default. Provides the ability of setting a
format for query parameter arrays. Handles request streaming mode (Content-Length and Transfer-Encoding headers).| Modifier and Type | Class and Description |
|---|---|
static class |
RestRequestBuilder.ParameterArrayFormat
COMMA: key=value1,value2,value3.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
NULL_URI_PARAMETER_ERROR_TEMPLATE |
static String |
PATH_PARAMETERS_NOT_USED_ERROR_TEMPLATE |
| Constructor and Description |
|---|
RestRequestBuilder(String baseUri,
String path,
org.mule.runtime.http.api.HttpConstants.Method method)
Creates a preconfigured
RestRequestBuilder per the given parameters. |
RestRequestBuilder(String baseUri,
String path,
org.mule.runtime.http.api.HttpConstants.Method method,
RequestParameters customParameters)
Creates a preconfigured
RestRequestBuilder per the given parameters. |
| Modifier and Type | Method and Description |
|---|---|
RestRequestBuilder |
addHeader(String key,
Object value)
Adds a header to the request builder.
|
RestRequestBuilder |
addQueryParam(String key,
Object value)
Adds a query parameter to the request builder.
|
RestRequestBuilder |
addUriParam(String placeholderKey,
Object value)
Adds an uri parameter to the request builder.
|
org.mule.runtime.http.api.domain.message.request.HttpRequest |
build() |
void |
clearHeaders()
Clears the header parameters configured for this request.
|
void |
clearQueryParams()
Clears the query parameters configured for this request.
|
void |
clearUriParams()
Clears the uri parameters configured for this request.
|
org.mule.runtime.api.util.MultiMap<String,String> |
getHeaders()
Returns an immutable map containing the headers configured for this request.
|
String |
getMethod()
Returns the HTTP verb to be used in this request
|
org.mule.runtime.api.util.MultiMap<String,String> |
getQueryParams()
Returns an immutable map containing the query parameters configured for this request.
|
HttpResponseInterceptorDescriptor |
getResponseInterceptorDescriptor() |
String |
getUri()
Returns the full uri for this request.
|
Map<String,String> |
getUriParams()
Returns an immutable map containing the uri parameters configured for this request.
|
RestRequestBuilder |
responseInterceptorDescriptor(HttpResponseInterceptorDescriptor httpResponseInterceptorDescriptor)
Describes a post process
HttpResponseInterceptorDescriptor to intercept and modify server's response before this is
mapped to a Result. |
RestRequestBuilder |
setBody(org.mule.runtime.api.metadata.TypedValue<InputStream> body,
StreamingType streamingType)
Defines the body and content streaming for this request.
|
void |
setFullUri(String fullUri)
Sets a full request URI that overrides the configured baseUri and path.
|
void |
setPath(String path)
Sets the path section for the request URI
|
RestRequestBuilder |
setQueryParamFormat(RestRequestBuilder.ParameterArrayFormat queryParamFormat)
Defines the format in which the query parameter arrays must be handled by this request.
|
public static final String PATH_PARAMETERS_NOT_USED_ERROR_TEMPLATE
public static final String NULL_URI_PARAMETER_ERROR_TEMPLATE
public RestRequestBuilder(String baseUri, String path, org.mule.runtime.http.api.HttpConstants.Method method)
RestRequestBuilder per the given parameters.
This creates a new RestRequestBuilder and initializes its URI and method.
The returned builder can still to add/change additional information.
baseUri - the base uri to be used.path - the path of the resource to request, relative to the base URI.method - the request method.public RestRequestBuilder(String baseUri, String path, org.mule.runtime.http.api.HttpConstants.Method method, RequestParameters customParameters)
RestRequestBuilder per the given parameters.
This creates a new RestRequestBuilder and initializes its URI, method, custom query params and custom headers.
The returned builder can still to add/change additional information.
baseUri - the base uri to be used.path - the path of the resource to request, relative to the base URI.method - the request method.customParameters - a list of custom request parameters that will always be sent in the final request.public String getUri()
public String getMethod()
public RestRequestBuilder addUriParam(String placeholderKey, Object value)
placeholderKey - The header name.value - The header value. Will be converted to string.public RestRequestBuilder addHeader(String key, Object value)
key - The header name.value - The header value. Will be converted to string.public RestRequestBuilder addQueryParam(String key, Object value)
key - The query parameter name.value - The query parameter value. Will be converted to string.public void clearUriParams()
public void clearQueryParams()
public void clearHeaders()
public Map<String,String> getUriParams()
public org.mule.runtime.api.util.MultiMap<String,String> getQueryParams()
public org.mule.runtime.api.util.MultiMap<String,String> getHeaders()
public RestRequestBuilder setQueryParamFormat(RestRequestBuilder.ParameterArrayFormat queryParamFormat)
queryParamFormat - The query parameter array formatpublic RestRequestBuilder setBody(org.mule.runtime.api.metadata.TypedValue<InputStream> body, StreamingType streamingType)
body - A TypedValue that contains the body to be sent in this request. Nullable.streamingType - The streaming type that must be used for this request's content.public RestRequestBuilder responseInterceptorDescriptor(HttpResponseInterceptorDescriptor httpResponseInterceptorDescriptor)
HttpResponseInterceptorDescriptor to intercept and modify server's response before this is
mapped to a Result.httpResponseInterceptorDescriptor - A HttpResponseInterceptorDescriptor to describe how to intercept server's
response.public HttpResponseInterceptorDescriptor getResponseInterceptorDescriptor()
HttpResponseInterceptorDescriptor to intercept and modify server's response before this is
mapped to a Result.public org.mule.runtime.http.api.domain.message.request.HttpRequest build()
public void setPath(String path)
path - the path of the request.public void setFullUri(String fullUri)
fullUri - to be set as the request URICopyright © 2023. All rights reserved.