Package io.micronaut.http.uri
Interface UriBuilder
-
public interface UriBuilder
Helper class for building URIs and handle encoding correctly.- Since:
- 1.0.2
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.net.URI
build()
The constructed URI.java.net.URI
expand(java.util.Map<java.lang.String,? super java.lang.Object> values)
Expands the URI if it is a template, using the given values.UriBuilder
fragment(java.lang.String fragment)
Sets the URI fragment.UriBuilder
host(java.lang.String host)
Sets the URI host.static UriBuilder
of(java.lang.CharSequence uri)
Create aUriBuilder
with the given base URI as a starting point.static UriBuilder
of(java.net.URI uri)
Create aUriBuilder
with the given base URI as a starting point.UriBuilder
path(java.lang.String path)
Appends the given path to the existing path correctly handling '/'.UriBuilder
port(int port)
Sets the URI port.UriBuilder
queryParam(java.lang.String name, java.lang.Object... values)
Adds a query parameter for the give name and values.UriBuilder
replacePath(java.lang.String path)
Replaces the existing path if any.UriBuilder
replaceQueryParam(java.lang.String name, java.lang.Object... values)
Adds a query parameter for the give name and values.UriBuilder
scheme(java.lang.String scheme)
Sets the URI scheme.UriBuilder
userInfo(java.lang.String userInfo)
Sets the URI user info.
-
-
-
Method Detail
-
fragment
@NonNull UriBuilder fragment(@Nullable java.lang.String fragment)
Sets the URI fragment.- Parameters:
fragment
- The fragument- Returns:
- This builder
-
scheme
@NonNull UriBuilder scheme(@Nullable java.lang.String scheme)
Sets the URI scheme.- Parameters:
scheme
- The scheme- Returns:
- This builder
-
userInfo
@NonNull UriBuilder userInfo(@Nullable java.lang.String userInfo)
Sets the URI user info.- Parameters:
userInfo
- The use info- Returns:
- This builder
-
host
@NonNull UriBuilder host(@Nullable java.lang.String host)
Sets the URI host.- Parameters:
host
- The host to use- Returns:
- This builder
-
port
@NonNull UriBuilder port(int port)
Sets the URI port.- Parameters:
port
- The port to use- Returns:
- This builder
-
path
@NonNull UriBuilder path(@Nullable java.lang.String path)
Appends the given path to the existing path correctly handling '/'. If path is null it is simply ignored.- Parameters:
path
- The path- Returns:
- This builder
-
replacePath
@NonNull UriBuilder replacePath(@Nullable java.lang.String path)
Replaces the existing path if any. If path is null it is simply ignored.- Parameters:
path
- The path- Returns:
- This builder
-
queryParam
@NonNull UriBuilder queryParam(java.lang.String name, java.lang.Object... values)
Adds a query parameter for the give name and values. The values will be URI encoded. If either name or values are null the value will be ignored.- Parameters:
name
- The namevalues
- The values- Returns:
- This builder
-
replaceQueryParam
@NonNull UriBuilder replaceQueryParam(java.lang.String name, java.lang.Object... values)
Adds a query parameter for the give name and values. The values will be URI encoded. If either name or values are null the value will be ignored.- Parameters:
name
- The namevalues
- The values- Returns:
- This builder
-
build
@NonNull java.net.URI build()
The constructed URI.- Returns:
- Build the URI
- Throws:
UriSyntaxException
- if the URI to be constructed is invalid
-
expand
@NonNull java.net.URI expand(java.util.Map<java.lang.String,? super java.lang.Object> values)
Expands the URI if it is a template, using the given values.- Parameters:
values
- Expands the URI with the given values.- Returns:
- Build the URI
-
of
@NonNull static UriBuilder of(@NonNull java.net.URI uri)
Create aUriBuilder
with the given base URI as a starting point.- Parameters:
uri
- The URI- Returns:
- The builder
-
of
@NonNull static UriBuilder of(@NonNull java.lang.CharSequence uri)
Create aUriBuilder
with the given base URI as a starting point.- Parameters:
uri
- The URI- Returns:
- The builder
-
-