Skip to content

Instantly share code, notes, and snippets.

@inancsevinc
Created July 2, 2012 07:18
Show Gist options
  • Select an option

  • Save inancsevinc/3031644 to your computer and use it in GitHub Desktop.

Select an option

Save inancsevinc/3031644 to your computer and use it in GitHub Desktop.
JAX-RS optional path params example
/**
* Returns most popular(retrieved using records in portal_log) documents opened using portal.
* This rest service responds all these requests:<br/>
* ../log/top ({p:/?} makes / optional)<br/>
* ../log/top/<br/>
* ../log/top/10 (same as ../log/top)<br/>
* ../log/top/20 (any number is fine)<br/>
*
* @param numberOfItems max number of items, default 10
* @return list of items containing cuid, rank and viewCount, ordered by viewCount desc
*/
@GET
@Path("/log/top{p:/?}{numberOfItems:([0-9]*)}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTopItems(@PathParam(value = "numberOfItems") int numberOfItems) {
try {
return Response.ok(portalLogDao.getTopItems(numberOfItems==0?10:numberOfItems)).build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment