Codehaus XFire

Documentation

Quicklinks

Developers

Sponsors

This page is for brainstorming how REST support should work in XFire (or possibly a new project if xfire ends up being too heavy weight).

Dan's First Take

Creating a Service

public class CustomerService {
  @RestMethod(methods={HttpMethod.GET}) 
  Customer getCustomer(String id);

  @RestMethod(methods={HttpMethod.DELETE}) 
  void deleteCustomer(String id);

  @RestMethod(methods={HttpMethod.POST}) 
  @WebResult(name="customerId")
  String addCustomer(Customer customer); 

  @RestMethod(method={HttpMethod.PUT})
  void updateCustomer(Customer customer);
}
public enum HttpMethod {
    DELETE,
    GET,
    PUT,
    POST
}

Mapping data to method parameters

The information to invoke our service could come from a number of places:

  • URI Path Info
    • @Path(2) - would select the first query parameter - i.e. "123" in "/customer/123"
    • @QueryParameter("customerId") - would select the query parameter with the name "customerId".
    • @RegexPath("someregexexpression") - would select some stuff from the uri
  • HTTP Headers
    • @HttpHeader("customerId") - would select the HTTP header with the name "customerId"
  • XML in a POST/PUT method
    • This can be done with JAXB, XMLBeans, etc.

Mapping the Operations to URIs

This could be done in the interface a couple different ways. At the class level:

@RestService(uri="/customer/")
public class CustomerService {
  ...
}

At the method level

public class CustomerService {
  @RestMethod(methods={HttpMethod.GET}, uri="/customer") 
  Customer getCustomer(String id);
...
}

At the service registration level:

CustomerService customerService = ...;
ServiceRegistry registry = ...;
registry.register("/internal-customers", customerService);
registry.register("/external-customers", anotherCustomerService);

Questions

  • What is the best way to map operations to URIs?
  • Is there a good syntax to map URI fragments to method parameters
  • What about MIME?
  • Should this framework allow non XML responses? i.e. could it return a JPEG? - the bigger question is can XFire support that....

I've been thinking of this same concept in ServiceMix to allow for direct exposure of endpoints via HTTP methods (i.e., mapping endpoints to HTTP methods). I figured that the endpoint name could be used as the endpoint portion of the URI. I'd really like to see these two concepts come together because I think that ServiceMix would then be able to support REST in a manner that is sufficiently simple but still powerful for users.

Posted by bsnyder at May 22, 2006 15:27

Yeah, that sounds like a good idea. Hiram echoed similar sentiments about method names.

Posted by dandiep at May 22, 2006 19:20