Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement REST in a web application?

I want to know how I could implement REST in my web application. I want to create a web application based on 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.

like image 317
Agusti-N Avatar asked Mar 31 '09 14:03

Agusti-N


People also ask

How is REST implemented?

The implementation consisted of moving the code from the JUnit tests into the APIs and then updating the tests to call those APIs. The modifyCertificate method, that provides the implementation for the certificates resource PUT method, was the most complex REST API to implement.


2 Answers

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.

like image 176
Phil H Avatar answered Nov 13 '22 02:11

Phil H


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.

like image 24
Florian Deissenboeck Avatar answered Nov 13 '22 02:11

Florian Deissenboeck