Class RestPathUtils
java.lang.Object
ru.vyarus.dropwizard.guice.url.util.RestPathUtils
Rest path utils. Useful for building resource paths based on resource classes and methods in application logic
(for example, building redirects).
There are two benefits of using classes directly:
- Simplified code navigation (obvious where this path leads)
- Safety: if the path changed in class, it would be counted here
- Since:
- 25.09.2025
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> RestPathBuilder<T>Build resource path from provided resource classe.static <T> RestPathBuilder<T>Build resource path from provided resource class.static <T> RestPathBuilder<T>buildSubResourcePath(@Nullable String basePath, Class<T> subResource, Object... args) Build resource path from provided sub-resource class.static StringgetResourcePath(@Nullable String basePath, Class<?> resource, Object... args) Build resource path from provided resource class.static StringgetResourcePath(Class<?> resource) Build resource path from provided resource class.
-
Method Details
-
getResourcePath
Build resource path from provided resource class.NOTE that this method should not be used for sub-resources, because their
Pathannotation is ignored (lookup method path used instead).- Parameters:
resource- resource class to build a path for- Returns:
- path for provided resource (or sub resource) with preserved path parameters placeholders
- Throws:
IllegalStateException- ifPathannotation not found in resource class hierarchy
-
getResourcePath
Build resource path from provided resource class.NOTE that this method should not be used for sub-resources, because their
Pathannotation is ignored (lookup method path used instead).- Parameters:
basePath- optional base path (could contain String.format() placeholders: %s)args- variables for path placeholders (String.format() arguments)resource- resource class to build a path for- Returns:
- path for provided resource (or sub resource) with preserved path parameters placeholders
- Throws:
IllegalStateException- ifPathannotation not found in resource class hierarchy
-
buildPath
Build resource path from provided resource class.- Type Parameters:
T- resource type- Parameters:
resource- resource class to build a path for- Returns:
- builder to specify path or query params
- Throws:
IllegalStateException- ifPathannotation not found in resource class hierarchy
-
buildPath
public static <T> RestPathBuilder<T> buildPath(@Nullable String basePath, Class<T> resource, Object... args) Build resource path from provided resource classe.- Type Parameters:
T- resource type- Parameters:
basePath- optional base path (could contain String.format() placeholders: %s)args- variables for path placeholders (String.format() arguments)resource- resource class to build a path for- Returns:
- builder to specify path or query params
- Throws:
IllegalStateException- ifPathannotation not found in resource class hierarchy
-
buildSubResourcePath
public static <T> RestPathBuilder<T> buildSubResourcePath(@Nullable String basePath, Class<T> subResource, Object... args) Build resource path from provided sub-resource class. IMPORTANT: the difference withbuildPath(String, Class, Object...)is thatPathannotation value is ignored for sub-resources (instead, the path from lookup method is used, which must be specified manually).- Type Parameters:
T- sub-resource type- Parameters:
basePath- sub resource mapping from locator method (could contain String.format() placeholders: %s)subResource- resource sub-resource class to build a path forargs- variables for path placeholders (String.format() arguments)- Returns:
- builder to specify path or query params
-