Quantcast
Viewing all articles
Browse latest Browse all 10

REST and Web development: new VRaptor and Restfulie releases

Since VRaptor 3 inception, the team has focused on good practices related to design issues such as “avoiding inheritance”, “ThreadLocal” and “public static mutable singletons”. Both releases keep their focus on design, less code, more results.
In one of its latest releases, VRaptor had a performance enhancement of 60% according to Lucas benchmarks. In an attempt to check Restfulie’s DSL impact in a project, a patch to Neo4J entire test suite results in 5% less code, compraing just the Rest client library code, the numbers are even higher.

VRaptor was an early adopter of Paul’s Paranamer and constructor DI, several years after its first public release, a typical controller is a simple:

@Resource
public class ClientsController {

  private final Clients clients;
  private final Result result;
  ClientsController(Clients clients,
                               Result result) {
     this.clients = clients;
     this.result = result;
  }

  @Post @Path("/clients")
  void add(Client client) {
    clients.save(client);
    result.redirectTo(ClientsController.class)
                  .show(client);
  }

  @Path("/clients/{example.id}")
  Client show(Client example) {
    return clients.find(example);
  }

}

VRaptor and Restfulie are refactor friendly: those who use Java must avoid “string based programming”, as shown in the redirection example, where renaming the show method, or changing its path will neither result in a failing test or failing feature.

VRaptor’s DI allows easy (real) unit testing as its coupling to its dependencies is minimized; and it is built on top of either Spring, Guice and PicoContainer.

Inheritance is only used to partially modify a component’s behavior and, if required, one own’s component can be provided with just one single annotation. Your models or controllers do not inherit dozens of methods that do not belong to your class domain, minimizing public method exposition.

Intercepting behavior is simple either on VRaptor (server) and Restfulie (client), through Interceptors and Request/ResponseFeatures. Creating components to be injected is also trivial such as the DAO from the Clients example:

@Component
class ClientDao implements Clients {
  // thats all
}

On the client side, Restfulie usage is straightforward and the default marshalling mechanism is provided through XStream:

String uri = "http://localhost:8000/clients/15";
Result r = Restfulie.at(uri).get();
System.out.println(r.getCode());

The at method has no side effect and is a domain entry point (instead of new). Navigating through hypermedia is also easy:

Result result = Restfulie.at(uri).get()
Client client = result.getResource();

result = resource(client).getLink("payments").get();

With such performance and code improvements,
VRaptor and Restfulie stay on track of not only solving problems, but following good design principles that try to minimize maintainance costs over time.


Viewing all articles
Browse latest Browse all 10

Trending Articles