Java REST Annotations
The Java REST annotations are annotations to help service creators build REST style services. Frameworks which wish to support REST can reuse these annotations just like the JSR181 & JAX-WS annotations are used across implementations. However, the idea with JRA is that many different frameworks (web, XML/SOAP, etc) may want to expose REST style services.
It is recognized that REST is an architecture not an implementation, and these annotations are geared around HTTP. So technically they should be called the Java HTTP Annotations, but then no one would no what we're talking about, leading us to chose the less correct name instead.
Projects Using JRA
- Apache CXF incubating
- Able (Coming soon!)
The Annotations
@HttpResource
The HttpResource annotation is used to map a bean or method to a resource. For instance:
@HttpResource(location="/customers") public List<Customer> getCustomers();
Or on a bean:
@HttpResource(location="/customers") public class Customers { List<Customer> get(); }
@Get/@Post/@Put/@Delete
The verb annotations map a method to a specific verb. Continuing on the above examples:
@Get @HttpResource(location="/customers") public List<Customer> getCustomers(); @Post @HttpResource(location="/customers") public void addCustomer(Customer customer);
Or on a bean:
@HttpResource(location="/customers") public class Customers { @Get List<Customer> get(); @Post void add(Customer customer); }
Mapping URI parameters
Parameters from the URI can be mapped through URI templating:
@HttpResource(location="/customers/{id}") public Customer getCustomer(String id);
Since java does not store the names of method parameters, frameworks will need to use some external means to map parameters to their names. Examples of this would be the @WebParam.name attribute from JAX-WS or Paranamer.
