#5 Handle sub-resource methods in client proxies

Public API (2)
Peter M. Murray

In the current implementation of client proxies, ProxyFactory.create() will throw if it encounters a method that has no HTTP method annotation associated with it (@GET, @POST, etc). However, elsewhere in the RESTEasy documentation, sub-resource accessor methods are described specifically as being annotated with @Path, but not with an HTTP method annotation. This indicates that these methods are navigational and the returned type is expected to be another appropriately annotated resource class.

In the client, it seems like it would make sense that the generated proxies could return new proxies instantiated based on the context passed in the method arguments. While the actual concrete return type of these methods need not be specified, the proxy could return an object of the type specified in the method declaration.

By way of example, consder the following two Service interfaces

public interface Book
String getTitle()

Chapter getChapter(@PathParam("number") int number)

public interface Chapter
public String getTitle();

public String getBody();

Once the Book service has been created, one could then invoke the getChapter() method to get an instance of the Chapter service interface pointed at a particular chapter.

It seems this could be done entirely on the client side without any REST calls as all of the information is available in the method invocation. The proxy would respond by creating a new proxy to the Chapter interface using the "number" parameter to complete the URI.

I have an implementation of this in the resteasy codebase and would be happy to submit a patch.


  • Patch file against 2.2.2GA

  • I uploaded a patch to 2.2.2GA which implements this feature - at least as much as I need for my use case. Probably it should allow for @QueryParam annotated method arguments as well...