Earthly Powers

Tuesday Aug 14, 2007

On Web resource mapping with JAX-RS

Bill de hÓra has a great blog entry on web resource mapping criteria for evaluating Web frameworks.

In the current JAX-RS API it is easy to do "function passing" or "surrogate". So following Bill's example...

The following is a resource using  the "function passing" approach:

@UriTemplate("document/xyz") 
public class FunctionPassingResource {

@HttpMethod

public InputStream getDocumentOrEditForm(@QueryParam("f") String f) {
if (f.equals("edit)) {
// return edit form representation
...
} else {
// return document representation
...
}
}

The following is a resource using  the "surrogate" approach:

@UriTemplate("document/xyz") 
public class FunctionPassingResource {

@HttpMethod

public InputStream getDocument() {
// return document representation
}

@UriTemplate("edit")
@HttpMethod
public InputStream getEditForm() {
// return edit form representation
}
}

IMHO JAX-RS is more suited to the "surrogate" approach. This approach is also used in the Atom server example of Jersey to distinguish between read only and read/write URIs of Atom entries. See the break down of the URIs here.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed