Pages

Friday, August 31, 2012

JAX-RS (RESTful Web Service) - Basics

JAX-RS (RESTful Web Service)

Three Main Packages

javax.ws.rs 
javax.ws.rs.core 
javax.ws.rs.ext

Reference Implementation from (ref. from wiki):

  • RESTeasy - from JBoss
  • Jersey - Sun (Oracle)
  • Apache CXF
  • Apache Wink
  • Restlet from Jerome Louvel


Primary Annotations:

@Path specifies the relative path for a resource class or method.
@GET, @PUT, @POST, @DELETE and @HEAD specify the HTTP request type of a resource.
@Produces specifies the response MIME media types.
@Consumes specifies the accepted request media types.

In addition, it provides further annotations to method parameters to pull information out of the request. All the @*Param annotations take a key of some form which is used to look up the value required.
@PathParam binds the parameter to a path segment.
@QueryParam binds the parameter to the value of an HTTP query parameter.
@MatrixParam binds the parameter to the value of an HTTP matrix parameter.
@HeaderParam binds the parameter to an HTTP header value.
@CookieParam binds the parameter to a cookie value.
@FormParam binds the parameter to a form value.
@DefaultValue specifies a default value for the above bindings when the key is not found.

Full example coming up... :)

No comments:

Post a Comment