Professional Documents
Culture Documents
2
What is REST?
• Stands for Representational State Transfer
• REST is a term defined by Roy Fielding in his PhD
dissertation. (2000)
• It is not a standard.
• It is an architectural style for networked systems
3
Principles of REST
• Everything gets an URI
– E.g. http://www.unionfilms.com/movies/
– http:// www.unionfilms.com/movies/ hangover/
• Link resources together
• Intuitively understandable URIs, resources, and actions
• Resource based, rather than service based
• Communicate statelessly
• The web itself is built on similar principles
4
Standard HTTP Methods
5
REST vs. SOAP
REST SOAP
• Resources oriented • Services oriented
6
JSON
• JavaScript Object Notation (JSON)
• Subset of the JavaScript Programming Language
• Lightweight data-interchange format
• JSON is text based
• Completely language independent
• Easy for humans to read and write
• Easy for machines to parse and generate
7
Benefits of JSON over XML
• JSON is lighter than XML.
8
JSON vs. XML
JSON example XML example
{ “movies” : <?xml version="1.0" ?>
[ <movies>
<movie>
{“year":2009,”name":“Hangover"},
<year>2009</year>
{“year":2009,"name":”2012"}
<name>Hangover</name>
] </movie>
} <movie>
<year>2009</year>
<name>2012</name>
</movie>
</movies>
9
Restlet Framework
• First development framework for REST
– Started in 2005 by Jérôme Louvel
– Enterprise Support provided by Noelios Technologies
– Large community
• Multiple editions for different targets available
– Java SE / EE, Google Web Toolkit, Google App Engine
10
Restlet Framework
• Architecture
– Used as a client and a server framework
– Restlet API defines the concepts
– Restlet Engine implements the API
• Restlet JAR-file only includes basic libraries
– Large number of Extensions is provided
11
Restlet Framework
• Application Object manages a set of related ServerResources
• ServerResource
– Each Object has an URI assigned
• http://localhost:8080/items
– Provides functionality by REST methods
• Get, Put, Post, Delete
• ClientResource
– Communicates with
ServerResource
12
Restlet Framework
• ServerResource implementation leveraging annotations
import org.restlet.resource.ServerResource
@Get(“json”)
public List<TestDataType> retrieve(){
//return data here
}
@Post()
public Representation create(TestDataType data){
//Create a new entry
}
13
Restlet Framework
• Request routing
– Defined in the corresponding Application Object
– Allows to route a specific URI to a ServerResource
import org.restlet.routing.Router
// Create a router
Router router = new Router(getContext());
14
Restlet Extensions
• All extensions in the Classpath will be integrated automatically
• ServerConnector
– Restlet JAR-file includes only a lightweight http server
– Servlet extension enables war deployment
• ClientConnector
– Restlet JAR-file allows to connect via http only
– Extensions for https, smtp
15
Restlet Extensions
• Converters
– Serialization of Java Objects is done automatically
– ConverterService for designated type (JSON) is required
– XStream allows to serialize as XML or JSON
@Get(“json”)
public List<TestDataType> retrieve(){
//return data here
}
16
Demonstration
17
Summary
• RESTful Web Services looks to be a solid growth area
• Restlet is very easy to use
– Many extensions available
– Very large user community and Enterprise support
– Framework leverages annotations
• Some of the features are new to Restlet 2.0
– This version is still in beta stage
18
Resources
• JSON
– http://www.json.org/
– http://www.json.org/java/
• Restlet Website
– http://www.restlet.org/
• Noelios Technologies offers Enterprise Support
– http://www.noelios.com/
19
Many thanks!
Any questions?