Class RestPathUtils

java.lang.Object
ru.vyarus.dropwizard.guice.url.util.RestPathUtils

public final class RestPathUtils extends Object
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 Details

    • getResourcePath

      public static String getResourcePath(Class<?> resource)
      Build resource path from provided resource class.

      NOTE that this method should not be used for sub-resources, because their Path annotation 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 - if Path annotation not found in resource class hierarchy
    • getResourcePath

      public static String getResourcePath(@Nullable String basePath, Class<?> resource, Object... args)
      Build resource path from provided resource class.

      NOTE that this method should not be used for sub-resources, because their Path annotation 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 - if Path annotation not found in resource class hierarchy
    • buildPath

      public static <T> RestPathBuilder<T> buildPath(Class<T> resource)
      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 - if Path annotation 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 - if Path annotation 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 with buildPath(String, Class, Object...) is that Path annotation 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 for
      args - variables for path placeholders (String.format() arguments)
      Returns:
      builder to specify path or query params