Rest
Rest
1
Hypertext Transfer Protocol (HTTP)
• A communications protocol
3
REST and HTTP
• The motivation for REST was to capture the
characteristics of the Web which made the Web
successful.
4
REST - not a Standard
• REST is not a standard
• JSR 311: JAX-RS: The JavaTM API for RESTful Web Services
5
Main Concepts
Nouns (Resources)
unconstrained
i.e., http://example.com/employees/12345
REST
Verbs Representations
constrained constrained
i.e., GET i.e., XML
6
Resources
• The key abstraction of information in REST is a
resource.
• http://www.boeing.com/aircraft/747
7
Verbs
• HTTP GET
• HTTP POST
• HTTP PUT
• HTTP DELETE
8
HTTP GET
• How clients ask for the information they seek.
• GET http://localhost/books
• Retrieve all books
• GET http://localhost/books/ISBN-0011021
• Retrieve book identified with ISBN-0011021
• GET http://localhost/books/ISBN-0011021/authors
• Retrieve authors for book identified with ISBN-0011021
9
HTTP PUT, HTTP POST
• POST http://localhost/books/
• Content: {title, authors[], …}
• Creates a new book with given properties
• PUT http://localhost/books/isbn-111
• Content: {isbn, title, authors[], …}
• Updates book identified by isbn-111 with submitted properties
10
HTTP DELETE
• DELETE http://localhost/books/ISBN-0011
• Delete book identified by ISBN-0011
11
Representations
• How data is represented or returned to the client for
presentation.
• XML
• XML
• <COURSE>
• <ID>CS2650</ID>
• <NAME>Distributed Multimedia Software</NAME>
• </COURSE>
• JSON
• {course
• {id: CS2650}
• {name: Distributed Multimedia Sofware}
• }
13
Why is it called
"Representational State Transfer"?
http://www.boeing.com/aircraft/747
Client Resource
Fuel requirements
Maintenance schedule
...
Boeing747.html
The Client references a Web resource using a URL. A representation of the resource is returned (in
this case as an HTML document).
The representation (e.g., Boeing747.html) places the client application in a state. The result of the
client traversing a hyperlink in Boeing747.html is another resource accessed. The new representation
places the client application into yet another state. Thus, the client application changes (transfers) state
with each resource representation --> Representation State Transfer!
14
Architecture Style
Web/Proxy Server
(XML doc)
doPost(id)
Request HTTP POST
(XML doc) URL 1 REST Engine
(locate resource
Response HTTP Response and generate
(JSON doc)
response) doDelete()
PO HTTP DELETE
(XML doc) URL 1
15
Real Life Examples
• Google Maps
• Amazon WebServices
16
REST and the Web
• All of those Web services that you have been using all
these many years - book ordering services, search
services, online dictionary services, etc - are REST-
based Web services.
17
REST Implementations
• Restlet
• http://www.restlet.org/
• Project Zero
• http://www.projectzero.org
• GlassFish Jersey
• https://jersey.dev.java.net/
• JBoss RESTeasy
• http://www.jboss.org/resteasy/
18
My Project - Web 2.0 IC Card
• Objective
• Transform the IC Card Application to support
REST resources
• http://www.cs.pitt.edu/icms/iccards
• http://www.cs.pitt.edu/icms/iccards/001
• http://www.cs.pitt.edu/icms/groups/1/users
19
Invocation Model
http http
SQL
Channels
Database 20
Tasks
21
References
22