Find file
Fetching contributors…
Cannot retrieve contributors at this time
107 lines (74 sloc) 3.1 KB


Build Status

when writing a java client app for rest based service, you must have duplication. You need to duplicate urls, paths, parameters type and order. What if you could just use an interface and call it's methods? It would send the correct http request, with all already done for you. vraptor-client aims to do that. It's a proxy handler implementation that will use the same interface that you use in the server's implementation, building correctly a request to the service.

For example, imagine a vraptor controller:

public class ClientController implements Clients{

    public String save(Client client) {"Saving client with name %s and age %d",, client.age));
        return "ok";


it implements Clients interface:

public interface Clients {

   String save(@Named("client") Client client);

int the client, you just have to inject the proxy implementation and use the interface:

public class ClientTest {

    Clients clients;

    public void test_save_client() {
        Client client = new Client();
        client.age = 25; = "andre";



git clone git://
cd vraptor-client
mvn install


vraptor does not use interfaces to obtain route information by default. To do that, you need to let vraptor use interfaces to obtain controller's information, using a customized route parser.

There's an implementation at:

Also, the controller's interfaces will need to use @Named annotation to indicate parameters name. Without that, paranamer won't be able to figure out params names.

The proxy handler classe is:

it needs three constructor arguments:

  • a class implementing - it will be in charge of doing the http requests
  • the base path for the request
  • a class implementing - it will parse the response and deal with exceptions

to create a proxy, you'll need to do:

Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { clazz },
                new RestProxyHandler(restClient, path, parser))

if you use spring, there is a factory bean to create the services for you

<bean name="factory" class="" />

it will need some beans:

  • a class implementing: - to make the http requests.
  • the base path for the request.
  • a class implementing: - it will inform which interfaces will be intercepted. If you want, you can use a use ClasspathScannerRestClassesProvider, and provide a base package to scan. Any interfaces will be loaded.
  • and finally, a class implementing: - it will parse the result from the request.