Java Reference
In-Depth Information
Accessing REST resources
As we said, REST resources can be accessed using actions that map an equivalent
HTTP request. In order to simplify the development of REST applications, you can
use simple annotations to map your actions; for example, in order to retrieve some
data from your application, you can use something similar to the following:
@Path("/users")
public class UserResource {
@GET
public String handleGETRequest() { . . .}
}
@POST
public String handlePOSTRequest(String payload)
{
}
The first annotation, @Path , used in our example is used to specify the URI that is
assigned to this web service. Subsequent methods have their specific @Path an-
notation so that you can provide a different response according to the URI reques-
ted.
Then, we have an @GET annotation that maps an HTTP GET request and an
@POST annotation that handles an HTTP POST . So in this example, if we were
to request for a web application bound to the web context example , an HTTP
GET request to the URL http://host/example/users would trigger the method
handleGETRequest ; while on the other hand, an HTTP POST request to the same
URL would conversely invoke the handlePOSTRequest method.
JBoss REST web services
Having understood the basics of REST services, let's see how we can develop a
RESTful web service using JBoss AS 7. The application server includes an out-of-
the-box RESTEasy library that is a portable implementation of the JSR-311 specific-
ation. RESTEasy is able to run in any servlet container; however, it is perfectly integ-
Search WWH ::




Custom Search