views:

886

answers:

5

Hi, i want to know how i could be implement REST in my web aplication. I want to create a web aplication based in this service, but i don't know how to do it. Now, i'm using J2EE and Tomcat. What things should be considered for these technologies?

EDIT: Sorry, i mean RESTful service.

+5  A: 

REST is not specific interface or technology, but a style. The best example is the web itself - your browser sends an HTTP request to a web server, which responds with a web page.

Representational State Transfer in this context: The representation is the web page, the state is the information contained in it. We could change the representation by switching to serving up xml instead of html, but the information would be the same.

In a RESTful service, you use this style to send data objects back and forth - the state is transferred from the server to you, and then you send a new state back again.

So, in a sense, Tomcat will already do REST for you, if you put your server pages as resources: http://carsales.com/cars/porsche2149 could be the resource for your car, to which you could use HTTP POST or PUT to change the details of it.

The hallmarks of REST are using URIs to denote resources, as above, using JSON or XML as the interchange medium (although AHAH and other formats are used), and arguing about how to DELETE collections.

First, work out what your resources will be, and organise your URI system to fit it (use URL rewriting etc). Then determine the representation(s) you want to use. Finally, write the backend to deal with passing state representations around, and update the database.

Phil H
Thanks Phil H, your answer it's really good and helpfull
Agusti-N
A: 

This is a bit of a drive-by answer, but if you want a framework/api to help here are two options:

Restlet

CXF's jax-rs

whaley
+1  A: 

I don't have any experience with CXF's jax-rs but Restlet works well for me. It allows to implement RESTful services and clients in a straightforward manner. It helped me a lot in programming against the REST service interface of DekiWiki. There's an O'Reilly book on "RESTful Web Service" that provides an ok introduction. It also has short section on Restlet.

A: 

We re also using Restlet with JAX-RS.

If you're gonna use JAX-RS (Java API for RESTful Web Services) then this document might be useful (although it is a reference guide for developing in JBoss RESTEasy).

I also recommend the REST test client

matali
A: 

RESTful Web Services is a book that might help you. It describes the incentive behind RESTful Web Services and gives instructions on how you should design your service. You then could move on the implementation either using a framework or just plain servlets.

As an alternative to the implementation methods already mentioned, I would like to add Spring MVC. It is possible to create RESTful applications already, but more direct support will be added in Spring 3.0

kgiannakakis