Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created December 20, 2010 22:29
Show Gist options
  • Save lucascs/749124 to your computer and use it in GitHub Desktop.
Save lucascs/749124 to your computer and use it in GitHub Desktop.
simple hypermedia example
public class Basket implements HypermediaResource {
private int id;
private String name;
public void configureRelations(RelationBuilder builder) {
builder.relation("self").uses(ItemController.class).showItem(id);
builder.relation("basket").at("/Basket/add/"+id);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Resource
public class ItemController {
private final Result result;
public ItemController(Result result) {
this.result = result;
}
@Get @Path("/items/{id}")
public void showItem(int id) {
Basket basket = new Basket();
basket.setId(id);
basket.setName("duh");
result.use(xml()).from(basket).serialize();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>vraptor-blank-project</display-name>
<context-param>
<param-name>br.com.caelum.vraptor.packages</param-name>
<param-value>br.com.caelum.vraptor.restfulie</param-value>
</context-param>
<filter>
<filter-name>vraptor</filter-name>
<filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
</filter>
<filter-mapping>
<filter-name>vraptor</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment