REST and AJAX Reconciled
REST and AJAX Reconciled
reconciled
Lars Trieloff at AJAX World East 2008
What is REST?
What is REST?
• Buzzword
What is REST?
• Buzzword
• Alternative to SOAP
What is REST?
• Buzzword
• Alternative to SOAP
• Representational State Transfer
What is REST?
• Buzzword
• Alternative to SOAP
• Representational State Transfer
• Architecture of the World Wide Web
What is REST?
• Buzzword
• Alternative to SOAP
• Representational State Transfer
• Architecture of the World Wide Web
• Architecture for Scalable Network Applications
How do we start?
• Introduction
• Core Concepts
• REST Clients
• AJAX REST Clients
• REST Frameworks
• REST Frameworks for AJAX
Things are Resources
Resource
Resource
URI
URI
URI
URI
Representation Representation
Resource Resource
Before After
GET is a “safe” method. There are no side-effects, and the
requested resource stays unmodified.
PUT is for replacing
PUT
Representation Representation
Resource Resource
Before After
PUT is a “idempotent” method. Issuing the same PUT
request multiple times yields the same result.
DELETE is for deleting
DELETE
Representation
Resource
Before After
DELETE is also “idempotent”. Deleting a resource twice
yields the same result - the resource is gone.
POST is for action
POST
Before After
POST is neither safe nor idempotent. It is used for updating,
creating and executing resources.
So what?
• There are unlimited resources
• Every resource can be addressed
• There are only four verbs
• Resources have an uniform interface
This makes it easy to write clients for existing REST
applications and makes it easy to expose a RESTful
interface to an application.
How do we go on?
• Introduction
• Core Concepts
• REST Clients
• AJAX REST Clients
• REST Frameworks
• REST Frameworks for AJAX
What are REST Clients
+ Desktop Applications
+Server-side mashups
- Not in the web browser
Web Browsers as HTTP Clients
+ No client needed
+Everywhere installed
- Weak HTTP Support
- Web Forms 1.0
- Browser Bugs
Web Forms 1.0
<form
action="/blog"
method="POST"
n / x - w w w - f o r m - u r l e n c o d e d ">
enctype="applicatio
o r m
f<label for="title">Title</label>
t yp e = "t e xt " n a m e = " t i t l e">
<input
f o r= " t ex t " > E nt r y < / l a b e l>
<label
<textarea name="text">
</textarea>
<input type="submit">
</form>
Web Forms 1.0
Why
o w d o I an do
d POS only GE
But h change w T T
oa
<fic rmlly o m
dy na m r g e t D r k an e t h o
c tioact(i
n toa
n = " /b lo g "
ELE d PU d s
the a mee)thoofdt=h"P"eOaSpplication/x-www-forTmE-uarrleencodeTda">nd
T "
AJAX
Where are we now?
• Introduction
• Core Concepts
• REST Clients
• AJAX REST Clients
• REST Frameworks
• REST Frameworks for AJAX
With AJAX we can
• get data-only (JSON) representations of
web pages in the background
• Resource-based approach?
• having something like /action/view/1 is a warning sign
• Apache Cocoon
• based on XML pipelines, URL patterns, selectors
• RESTlet
• Like Servlets for REST. Good for existing models
• Apache Sling
• based on JCR, a database for resources, with server-
side scripting support
How do we go on?
• Introduction
• Core Concepts
• REST Clients
• AJAX REST Clients
• REST Frameworks
• REST Frameworks for AJAX
Sling with µjax
• Exposes the complete JCR repository
(Resource Database) as JSON tree
resource or
http://l iented urls inte grat ion
dojo widget
ocalhost
:7402/my
data/ent
ries.lis
t.html
Never leave without
screenshots