Class RestPathBuilder<T>

java.lang.Object
ru.vyarus.dropwizard.guice.url.resource.ResourceParamsBuilder
ru.vyarus.dropwizard.guice.url.RestPathBuilder<T>
Type Parameters:
T - resource type

public class RestPathBuilder<T> extends ResourceParamsBuilder
Resource path builder. Used to build rest path using resource class and methods.

Sub resources could be specified with subResource(String, Class, Object...).

Path parameters and additional query parameters could be resolved with ResourceParamsBuilder.pathParam(String, Object) and ResourceParamsBuilder.queryParam(String, Object...). Note that when resource path is built from method, required path and query parameters could be specified as resource methods arguments (method(ru.vyarus.dropwizard.guice.url.util.Caller)).

Final path could be built either as template (preserving path parameters) ResourceParamsBuilder.buildTemplate() or as final path with resolved path parameters ResourceParamsBuilder.build().

Since:
26.09.2025
See Also:
  • Constructor Details

    • RestPathBuilder

      public RestPathBuilder(@Nullable String basePath, Class<T> resource, boolean subResource)
      Create a builder.

      Note that jersey ignores Path annotation for sub resources (only lookup method path is used)

      Parameters:
      basePath - optional base path
      resource - target resource
      subResource - true if it is a sub resource (important because @Path annotation must be ignored)
  • Method Details

    • subResource

      public <K> RestPathBuilder<K> subResource(String path, Class<K> subResource, Object... args)
      Append a sub-resource path to the current resource path (with sub-resource method resolution).

      Sub-resource path is declared by a sub-resource method: @Path("/sub") SubResource something() {...}. Here sub-resource path would include path from declaration method and path, declared for sub-resource class. The current method does not search for tareget declaration method (in some cases it is impossible), so sub-resource mapping path (from method) must be applied manually.

      Type Parameters:
      K - sub-resource type
      Parameters:
      path - sub-resource mapping path (from sub-resource method; could contain String.format() placeholders: %s)
      subResource - sub-resource
      args - args variables for path placeholders (String.format() arguments)
      Returns:
      builder for sub-resource
    • subResource

      public <K> RestPathBuilder<K> subResource(Caller<T> caller, Class<K> subResource)
      Append a sub-resource path to the current resource path. Sub resource path is resolved through the called locator method.

      Note: multiple locator methods could be called at once!

      Type Parameters:
      K - sub-resource type
      Parameters:
      caller - locator method(s) caller
      subResource - sub-resource type
      Returns:
      builder for sub-resource
    • path

      public ResourceParamsBuilder path(String path, Object... args)
      Append provided path to resource path (useful when direct resource method can't be used for construction).

      Query parameters could be specified directly.

      Parameters:
      path - target path, relative to resource root (could contain String.format() placeholders: %s)
      args - variables for path placeholders (String.format() arguments)
      Returns:
      parameters builder to specify path and query parameters
      See Also:
    • method

      public ResourceParamsBuilder method(String methodName, Class<?>... parameters)
      Append resource method path (path from Path method annotation).

      When parameters are not provided - search for any method with name. If multiple methods with the same name would be found - method with no parameters would be selected, otherwise exception thrown.

      Parameters:
      methodName - method name
      parameters - method argument types
      Returns:
      parameters builder to specify path and query parameters
      Throws:
      IllegalStateException - if no unique method found for provided name
      See Also:
    • method

      public ResourceParamsBuilder method(Method method)
      Append resource method path (path from Path method annotation).
      Parameters:
      method - resource method
      Returns:
      parameters builder to specify path and query parameters
      See Also:
    • method

      public ResourceParamsBuilder method(Caller<T> caller)
      Append resource method path (path from Path method annotation). Also, use path and query providers, provided as method arguments. Note that only non-null parameters counted.

      Might also include sub resource call, if sub resource locator method returns resource instance: resource.sub(args).method(args)

      Parameters:
      caller - consumer with exactly one resource method execution
      Returns:
      parameters builder to specify path and query parameters