public interface UriBuilder
Effectively a generalization of UriComponentsBuilder but with
shortcuts to expand directly into URI rather than
UriComponents and also leaving common concerns such as encoding
preferences, a base URI, and others as implementation concerns.
Typically obtained via UriBuilderFactory which serves as a central
component configured once and used to create many URLs.
UriBuilderFactory,
UriComponentsBuilder| Modifier and Type | Method and Description |
|---|---|
URI |
build(Map<String,?> uriVariables)
Build a
URI instance and replaces URI template variables
with the values from a map. |
URI |
build(Object... uriVariables)
Build a
URI instance and replaces URI template variables
with the values from an array. |
UriBuilder |
fragment(String fragment)
Set the URI fragment.
|
UriBuilder |
host(String host)
Set the URI host which may contain URI template variables, and may also
be
null to clear the host of this builder. |
UriBuilder |
path(String path)
Append the given path to the existing path of this builder.
|
UriBuilder |
pathSegment(String... pathSegments)
Append path segments to the existing path.
|
UriBuilder |
port(int port)
Set the URI port.
|
UriBuilder |
port(String port)
Set the URI port .
|
UriBuilder |
query(String query)
Append the given query to the existing query of this builder.
|
UriBuilder |
queryParam(String name,
Object... values)
Append the given query parameter to the existing query parameters.
|
UriBuilder |
queryParams(MultiValueMap<String,String> params)
Add the given query parameters.
|
UriBuilder |
replacePath(String path)
Set the path of this builder overriding the existing path values.
|
UriBuilder |
replaceQuery(String query)
Set the query of this builder overriding all existing query parameters.
|
UriBuilder |
replaceQueryParam(String name,
Object... values)
Set the query parameter values overriding all existing query values for
the same parameter.
|
UriBuilder |
replaceQueryParams(MultiValueMap<String,String> params)
Set the query parameter values overriding all existing query values.
|
UriBuilder |
scheme(String scheme)
Set the URI scheme which may contain URI template variables,
and may also be
null to clear the scheme of this builder. |
UriBuilder |
userInfo(String userInfo)
Set the URI user info which may contain URI template variables, and
may also be
null to clear the user info of this builder. |
UriBuilder scheme(@Nullable String scheme)
null to clear the scheme of this builder.scheme - the URI schemeUriBuilder userInfo(@Nullable String userInfo)
null to clear the user info of this builder.userInfo - the URI user infoUriBuilder host(@Nullable String host)
null to clear the host of this builder.host - the URI hostUriBuilder port(int port)
-1 will clear the port of this builder.port - the URI portUriBuilder port(@Nullable String port)
port(int).
Passing null will clear the port of this builder.port - the URI portUriBuilder path(String path)
path - the URI pathUriBuilder replacePath(@Nullable String path)
path - the URI path, or null for an empty pathUriBuilder pathSegment(String... pathSegments) throws IllegalArgumentException
path("/") subsequently to ensure a trailing slash.pathSegments - the URI path segmentsIllegalArgumentExceptionUriBuilder query(String query)
Note: The presence of reserved characters can prevent
correct parsing of the URI string. For example if a query parameter
contains '=' or '&' characters, the query string cannot
be parsed unambiguously. Such values should be substituted for URI
variables to enable correct parsing:
builder.query("filter={value}").uriString("hot&cold");
query - the query stringUriBuilder replaceQuery(@Nullable String query)
query - the query string, or null to remove all query paramsUriBuilder queryParam(String name, Object... values)
?foo instead of ?foo=bar.name - the query parameter namevalues - the query parameter valuesUriBuilder queryParams(MultiValueMap<String,String> params)
params - the paramsUriBuilder replaceQueryParam(String name, Object... values)
name - the query parameter namevalues - the query parameter valuesUriBuilder replaceQueryParams(MultiValueMap<String,String> params)
params - the query parameter nameUriBuilder fragment(@Nullable String fragment)
null to clear the fragment of this builder.fragment - the URI fragmentURI build(Object... uriVariables)
URI instance and replaces URI template variables
with the values from an array.uriVariables - the map of URI variables