Restlet 2.0

burnwholeInternet and Web Development

Feb 5, 2013 (4 years and 2 months ago)

127 views

Restlet Framework 2.0

Going to discuss about…


What is REST?


REST Concept.


REST Architecture.


REST Guiding Principles.


Benefits and Drawbacks.


REST Frameworks.


Restlet 2.0



REST
-

Representational State
Transfer


REST

is a way to access documents and resources using a simple
remote software architecture, represented by an API.



RE
presentational
S
tate
T
ransfer was introduced and defined in 2000
by
Roy Fielding
in his doctoral dissertation.



Fielding

is one of the principal authors of the Hypertext Transfer
Protocol (
HTTP
) specification versions
1.0

and
1.1



The
REST

architecture does not necessarily use
HTTP

or the
Web
.



The largest known implementation of a system conforming to the
REST architectural style is the World Wide Web. The WWW (
W
orld
W
ide
W
eb) is an application of the
REST

architecture.




Simply put, REST means using HTTP the way it's meant to be.

REST Concept


REST
-
style architectures consist of clients and servers.



Clients

initiate requests to
servers
;
Servers

process requests and
return appropriate responses.



Requests and responses are built around the transfer of
representations of resources
.



A
resource

can be essentially any coherent and meaningful concept
that may be addressed.



A
representation of a resource
is typically a document that
captures the current or intended state of a resource.



REST Architecture


REST

architecture is defined as follows:



States and functions of a remote application are considered as
resources.



Each resource is only accessible using a standard address.
These are hyper links. Under
HTTP

these are
URIs
.



Resources have a standard interface in which the transactions
and data types are precisely defined.
XML

or
JSON

for example,
or
HTML
.


Date exchange is carried out according to a protocol that has
the following properties


Client
-
server
.


Without states
(states may be represented by
variables).


Enables caching
.


In several
software layers
.


Independence of the interface against added services such as
proxies, firewalls, gateways and others.


REST Guiding Principles



Guiding principles
:


Identification of resources through URI.


Use standard methods like GET, PUT, DELETE and POST for
manipulation of resources (stick to the methods provided by the
protocol ).


Self
-
descriptive messages due to statelessness.


Representation oriented. (interact with services using
representations of that service ).

Benefits & Drawbacks


Benefits:


Easier to implement than the alternatives.


Just a browser to access a service.


Make good use of HTTP cache and proxy server.


Less memory consumption

than others.


No need to add beyond the contributions of HTTP.


Using standard formats as
HTML

or
XML

ensures compatibility
over time (no SOAP envelope to wrap every call in ).


Independent deployment of components (i.e.., reducing
client/server coupling).



Drawbacks:


The data necessary to use the service must be known already.


Less

secure

than architectures based on protocol as
SOAP
.


In SOAP, like
WS
-
Security

that lets you encrypt only portions of
the messages.

Dominant RESTFul Services


Examples



Amazon AWS
: They offer Services for Storage (S3) and they have
SOAP and REST interfaces but over 90% of the clients are using REST.



Google Maps

is using RESTful services to provide cacheable map tiles.



Yahoo API’s

are mostly build with RESTful interfaces.


REST Frameworks


Framework implementations


.
NET Open
-
Source



OpenRasta.


ColdFusion

-

ColdFusion on Wheels, Mach
-
II, Taffy.


Ext JS
.


Java

-

Jt Design Pattern Framework, Wink ,
Restlet
, JBoss RESTEasy,
Jersey, Apache CXF, NetKernel, Apache Sling, Restfulie, Play
Framework.


Microsoft's
Azure Services Platform and WCF Data Services.


PHP
DooPHP, Symfony, Zend Framework, CakePHP, Kohana,
CodeIgniter, Sapphire, FRAPI, RECESS.


REST microkernel
and software platform NetKernel.


Ruby

Ruby on Rails, Sinatra, Restfulie.


TurboGears2

provides a RestController.


ZEST
-

lightweight Struts
-
like Web framework.

Restlet
-

Introduction


Restlet

is a lightweight, comprehensive, open source REST
framework for the Java platform.


Restlet

is suitable for both server and client Web applications.


Restlet

supports major
Internet transport
,
data

format
, and
service description standards like
HTTP

and
HTTPS
,
SMTP
,
XML
,
JSON
,
Atom(
is an XML language used for web feeds), and
WADL
.


Restlet

directly models the concepts (Resource, Representation,
Connector, Component, etc.) from Roy T. Fielding's original
dissertation on the architecture of the Web.


Stable release

2.0.4 / December 24, 2010

Development status

Active

Written in

Java

Organization

Noelios Technologies

Website

http://www.restlet.org/

Multiple Editions


Restlet 2.0
has been reworked to provide separate distributions for
each edition:


Java

SE

:

This

is

the

usual

distribution

previously

available

in

version

1
.
1
,

without

the

Servlet

related

extensions
.


Java

EE

(with

Servlet

support)
:


This

is

the

usual

distribution

previously

available

in

version

1
.
1
,

without

the

standalone

connectors

such

as

Jetty,

Grizzly,

Netty

or

Simple
.


Google

Web

Toolkit
:

This

edition

is

based

on

the

Java

EE

edition

as

GAE

requires

the

deployment

of

web

applications

in

a

constrained

Servlet

container
.


Google

App

Engine

:

GAE

is

a

platform

for

developing

and

hosting

web

applications

in

Google
-
managed

data

centers
.

GWT

object

serialization

support,

based

on

annotated

Restlet

interfaces

was

also

added

for

the

GWT

edition,

leveraging

GWT’s

deferred

binding

mechanism

and

GWT
-
RPC

serialization

format
.



Android
:


Port

of

the

Crypto,

Apache

HTTP

Client,

JAAS,

JSON,

Net

extension

(without

FTP

client)
.


Extensions

1.
Crypto

extension

11.
Netty

extension

2.
FreeMarker

extension

12.
OData

extension

3.
GWT

extension (server
-
side)

13.
RDF

extension

4.
HTTP Client

extension (Apache)

14.
ROME

extension

5.
JAAS

extension

15.
Servlet

extension

6.
Jackson

extension

16.
SLF4J

extension

7.
JAX
-
RS
extension

17.
Spring

extension

8.
Jetty
extension

18.
XML

extension

9.
Lucene

extension

19.
XStream
extension

10.
Net

extension



The

Restlet

Framework

lets

you

build

complete

Web

applications

by

itself

and

is

capable

of

leveraging

other

open

source

projects

to

facilitate

tasks

such

as

generation

of

dynamic

representations,

management

of

uploaded

files,

sending

of

mails,

etc
.



Restlet overview


The Restlet Framework is composed of two parts:


The Restlet Core



Restlet API
(neutral API supporting the concepts of REST and facilitating
the handling of calls for both client
-
side and server
-
side applications) +
Restlet Engine
implementing the API.



Optional Restlet extensions


Restlet API


Restlet API

is a small set of packages, with classes, interfaces and
enumerations that together provide a framework.


This framework will guide you on the path to RESTful design and
development.

API Packages


Base

package
:

This

org
.
restlet

package

contains

the

core

classes

of

the

API,

mapping

REST

concepts

such

as

Uniform,

Component

and

Connector
.


Data

package
:

The

org
.
restlet
.
data

package

contains

Information

exchanged

by

components
.

In

particular,

it

contains

Java

classes

mapping

most

HTTP

headers
.


Resource

package
:

The

org
.
restlet
.
resource

package

contains

client

and

server

resource

classes
.


Security

package
:

The

org
.
restlet
.
security

package

contains

classes

related

to

security
.



As

there

are

numerous

protocols

(like

HTTP,

SMTP,

etc
.
)

that

we

want

to

support

and

as

each

one

has

various

ways

to

authenticate

requests

(HTTP

Basic,

HTTP

Digest,

SMTP

Plain,

etc
.
),

the

Restlet

API

provides

a

flexible

mechanism

to

support

them

all

in

a

unified

way
.




API Packages…


Service

package
:

The

org
.
restlet
.
service

package

contains

services

used

by

applications

and

components
.



Util

package
:

The

org
.
restlet
.
util

package

contains

various

utility

classes
.


Representation

package
:

The

org
.
restlet
.
representation

package

contains

common

representation

data

elements
.

Here

is

a

hierarchy

diagram

with

the

core

Representation

classes
.


Representation package

Mapping HTTP headers

HTTP Header

Restlet Property Name

Accept

request.clientInfo.acceptedMediaTypes

Accept
-
Charset

request.clientInfo.acceptedCharacterSets

Accept
-
Encoding

request.clientInfo.acceptedEncodings

Accept
-
Language

request.clientInfo.acceptedLanguages

Accept
-
Ranges

response.serverInfo.acceptRanges

Age

response.age

Allow

response.allowedMethods

Authentication
-
Info

response.authenticationInfo

Authorization

request.challengeResponse

Cache
-
Control

message.cacheDirectives

Mapping HTTP headers…

HTTP Header

Restlet Property Name

Connection

[HTTP connectors]

Content
-
Disposition

message.entity.disposition

Content
-
Encoding

message.entity.encodings

Content
-
Language

message.entity.languages

Content
-
Length

message.entity.size

Content
-
Location

message.entity.locationRef

Content
-
MD5

message.entity.digest

Content
-
Range

message.entity.range

Content
-
Type

message.entity.mediaType and
characterSet

Cookie

request.cookies

Mapping HTTP headers…

HTTP Header

Restlet Property Name

Date

message.date

ETag

message.entity.tag

Expect

request.clientInfo.expectations

Expires

message.entity.expirationDate

From

request.clientInfo.from

Host

request.hostRef

If
-
Match

request.conditions.match

If
-
Modified
-
Since

request.conditions.modifiedSince

If
-
None
-
Match

request.conditions.noneMatch

If
-
Range

request.conditions.rangeTag and rangeDate

Mapping HTTP headers…

HTTP Header

Restlet Property Name

If
-
Unmodified
-
Since

request.conditions.unmodifiedSince

Last
-
Modified

message.entity.modificationDate

Location

response.locationRef

Max
-
Forwards

request.maxForwards

Pragma

[Deprecated]

Proxy
-
Authenticate

response.proxyChallengeRequests

Proxy
-
Authorization

request.proxyChallengeResponse

Range

request.ranges

Referer

request.refererRef

Retry
-
After

response.retryAfter

Mapping HTTP headers…

HTTP Header

Restlet Property Name

Server

response.serverInfo.agent

Set
-
Cookie

response.cookieSettings

Set
-
Cookie2

response.cookieSettings

TE

-

Trailer

-

Transfer
-
Encoding

[HTTP connectors]

Upgrade

-

User
-
Agent

request.clientInfo.agent

Vary

response.dimensions

Via

message.recipientsInfo

Mapping HTTP headers…

HTTP Header

Restlet Property Name

Warning

message.warnings

WWW
-
Authenticate

response.challengeRequests

X
-
Forwarded
-
For

request.clientInfo.addresses

X
-
HTTP
-
Method
-
Override

[Tunnel service]

Restlet Engine


Restlet engine
is the set of classes that supports or implements the
Restlet API. Since version 2.0, the Restlet API and Engine have been
merged in a single "
org.restlet.jar
" file.


Here is the list of connectors built
-
in the Restlet engine:


Local


FILE


CLAP (
C
lass
L
oader
A
ccess
P
rotocol)


HTTP (HyperText Transfer protocol )


RIAP (
R
estlet
I
nternal
A
ccess
P
rotocol)


Zip

Glossary

1.Application

13.Representation

2.Authenticator

14.Request

3.Authorizer

15.Resource

4.Client

16.Response

5.Component

17.Restlet

6.Connector

18.Route

7.Context

19.Router

8.Directory

20.Server

9.Engine

21.Transformer

10.Filter

22.Uniform

11.Finder

23.Virtual Host

12.Redirector

Glossary…


Application:

Restlet that can be attached to one or more Virtual
Hosts. Applications are guaranteed to receive calls with their base
reference set relatively to the Virtual Host that served them. This
class is both a descriptor able to create the root Restlet and the
actual Restlet that can be attached to one or more Virtual Host
instances.


Authenticator:

Filter authenticating the client sending the request
based on mechanisms such as challenge request and response or
SSL certificates.


Authorizer:

Filter authorizing requests based on flexible criteria's
such as method name, client role.


Client:
Connector acting as a generic client. It internally uses one of
the available connectors registered with the current Restlet
implementation.

Glossary…


Component:

Restlet managing a set of Clients, Servers and other
Restlets. Component managing a set of Virtual Hosts and
Applications. Applications are expected to be directly attached to
Virtual Hosts.


Connector:

Restlet enabling communication between Components.
Encapsulate the activities of accessing resources and transferring
resource representations.


Context:
The context is the means by which a Restlet may access
the software environment within the framework.


Directory:

Handler mapping a directory of local resources.


Engine:

A Restlet Engine is an implementation of the Restlet API.
The reference implementation, provided by Noelios Technologies,
is therefore called the Noelios Restlet Engine (NRE).

Glossary…


Filter:

Used to do some pre
-
processing or post
-
processing on the
calls going through it before or after they are actually handled by
an attached Restlet.


Finder:

Restlet that can find the target resource that will concretely
handle the request.


Redirector:

Rewrites URIs then redirects the call or the client to a
new destination.


Representation:
Current or intended state of a resource.


Request:
Generic request sent by client connectors. This request
can also be processed by a chain of Restlets, on the client or server
sides.


Resource:

Intended conceptual target of a hypertext reference.


Glossary…


Response:

Generic response sent by server connectors. It is then
received by client connectors. Responses are uniform across all
types of connectors, protocols and components.


Restlet:

Dispatcher that provides a context and life cycle support.


Route:
Filter scoring the affinity of calls with the attached Restlet.
The score is used by an associated Router in order to determine the
most appropriate Restlet for a given call.


Router:

Restlet routing calls to one of the attached routes. Several
routing modes are supported, implementing various algorithms:


Best match (default)


First match


Last match


Random match


Round robin


Custom

Glossary…


Server:
Connector acting as a generic server.


Transformer:
Filter that can transform XML representations by
applying an XSLT transform sheet.


Uniform:
Base class exposing a uniform REST interface. It has many
subclasses that focus on a specific ways to handle calls like filtering,
routing or finding a target resource.


Virtual Host:

Router of calls from Server connectors to Restlets.
The attached Restlets are typically Applications.

Thank you!


This PPT(Restlet 2.0.ppt ) is available for your references in
Trac

under
Wiki

>
Tek
-
Talk

>
Topic

Explanation

&
Discussions

>
Non
-
Selectsite
.



URL for your reference:


http://www.restlet.org/documentation/


http://blog.noelios.com/2010/07/19/restlet
-
framework
-
2
-
0
-
0
-
released/


http://en.wikipedia.org/wiki/Restlet


http://www.infoq.com/articles/rest
-
introduction


http://oracled.wordpress.com/2009/03/11/when
-
to
-
use
-
rest
-
based
-
web
-
services/


http://www.deitel.com/ResourceCenters/Programming/RESTWebServi
ces/RESTWebServicesRESTvsSOAP/tabid/3047/Default.aspx