2. 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 in a new state.
When the client selects a hyperlink in Boeing747.html, it accesses another
resource.
The new representation places the client application into yet another state.
Thus, the client application transfers state with each resource representation.
3. " REST " was coined by Roy Fielding
in his Ph.D. dissertation [1] to describe a design
pattern for implementing networked systems.
REST is not even an architecture
REST is not a standard.
Why?
4. REST is a design pattern.
It is a certain approach to creating Web Services.
REST is a lightweight alternative to mechanisms like
RPC (Remote Procedure Calls) and Web Services
(SOAP, WSDL, etc.).
It relies on a stateless, client-server, cacheable
communications protocol -- and in virtually all
cases, the HTTP protocol is used.
5. While REST is not a standard, it does use standards:
1. HTTP
2. URL
3. XML/HTML/GIF/JPEG/etc. (Resource
Representations)
4. text/xml, text/html, image/gif, image/jpeg, etc.
(MIME Types)
6. Client-Server: a pull-based interaction style: consuming
components pull representations.
Stateless: each request from client to server must contain all the
information necessary to understand the request, and cannot
take advantage of any stored context on the server.
Named resources - the system is comprised of resources which
are named using a URL.
Uniform interface: allresources are accessed with a generic
interface (e.g., HTTP GET, POST, PUT, DELETE).
8. • The REST design pattern is best explained with an
example.
• I will present an example of a company deploying
three Web services using the REST design pattern.
9. Suppose that an airline wants to create a telephone
reservation system for customers to call in and make
flight reservations.
The airline wants to ensure that its premier members
get immediate service, its frequent flyer members get
expedited service and all others get regular service.
There are two main approaches to implementing the
reservation service...
10. The airline provides a single telephone number.
Upon entry into the system a customer encounters an
automated message, "Press 1 if you are a premier
member, press 2 if you are a frequent flyer, press 3 for all
others."
Premier
Customer
Representative
Premier Members
F.F.
Answering
Airline Reservations Customer
Machine Representative
Frequent Flyer Members
Regular
Customer
Representative
Regular Members
11. The airline provides several telephone numbers - one
number for premier members, a different number for
frequent flyers, and still another for regular customers.
Premier
1-800-Premier Customer
Representative
Premier Members
F.F.
1-800-Frequent Customer
Representative
Frequent Flyer Members
Regular
1-800-Reservation Customer
Representative
Regular Members
12. Suppose now the airline (kings-air.com) wants to provide a
Web reservation service for customers to make flight
reservations through the Web.
Just as with the telephone service, the airline wants to
ensure that its premier members get immediate service, its
frequent flyer members get expedited service, all others get
regular service.
There are two main approaches to implementing the Web
reservation service.
13. The airline provides a single URL. The Web service
is responsible for examining incoming client
requests to determine their priority and process
them accordingly.
client
Premier
Premier Members Customer
Web Determine F.F.
client Reservation Priority Customer
Frequent Flyer Members Service
Regular
Customer
client
Regular Members
14. There is currently no industry accepted practice (rules)
for expressing priorities, so rules would need to be
made. The clients must learn the rule, and the Web
service application must be written to understand the
rule.
This approach is based upon the incorrect assumption
that a URL is "expensive" and that their use must be
rationed.
Load balancing is a challenge.
It violates Tim Berners-Lee Web Design, Axiom 0 (see
next slide).
15. Axiom 0: all resources on the Web must be
uniquely identified with a URI.
URL1
resource1
URL2
resource2
URL3
resource3
16. The airline provides several URLs - one URL for
premier members, a different URL for frequent
flyers, and still another for regular customers.
Premier
http://www.kings-air/reservations/premier Member
client Reservation
Premier Members Service
Frequent
http://www.kings-air/reservations/frequent-flyer Flyer
client Reservation
Service
Frequent Flyer Members
Regular
http://www.kings-air/reservations/regular Member
client Reservation
Service
Regular Members
17. The different URLs are discoverable by search engines and
UDDI registries.
It's easy to understand what each service does simply by
examining the URL, i.e., it exploits the Principle of Least
Surprise.
There is no need to introduce rules. Priorities are elevated
to the level of a URL. "What you see is what you get."
It's easy to implement high priority - simply assign a fast
machine at the premier member URL.
There is no bottleneck. There is no central point of failure.
Consistent with Axiom 0.
18. We have looked at a reservation service.
We have seen a telephone-based version and a Web-
based version of the reservation service.
With each version we have seen two main approaches
to implementing the service.
Which approach is the REST design pattern and which
isn't? See the following slides.
19. This Isn't the
Premier
Customer
Representative
Premier Members
F.F.
Answering
Airline Reservation Customer
Machine Representative
Frequent Flyer Members
Regular
Customer
Representative
Regular Members
20. This is the
Premier
1-800-Premier Customer
Representative
Premier Members
F.F.
1-800-Frequent Customer
Representative
Frequent Flyer Members
Regular
1-800-Reservation Customer
Representative
Regular Members
21. client
Premier
Premier Members Customer
Reservation Determine F.F.
client Web Priority Customer
Frequent Flyer Members Service
Regular
Customer
client
Regular Members
22. Premier
http://www.kings-air/reservations/premier Member
client Reservation
Premier Members Service
Frequent
http://www.kings-air/reservations/frequent-flyer Flyer
client Reservation
Frequent Flyer Members Service
Regular
http://www.kings-air/reservations/regular Member
client Reservation
Service
Regular Members
23. Resources
URLs Simple Operations
We discussed how Resources and URLs are fundamental to REST. In a follow up
we will discuss how Simple Operations are also fundamental to REST.
24. Summary of the
REST Design Pattern
Create a resource for every service.
Uniquely identify each resource with a logical URL.
All interactions between a client and a web service are
done with simple operations. Most web interactions
are done using HTTP and just four operations:
25. HTTP provides a simple set of operations.
Amazingly, all Web exchanges are done using this
simple HTTP API:
GET = "give me some info" (Retrieve)
POST = "here's some update info" (Update)
PUT = "here's some new info" (Create)
DELETE = "delete some info" (Delete)
The HTTP API is CRUD
(Create, Retrieve, Update, and Delete)
27. 1. A SOAP (Simple Object Access Protocol) service (WS-) has a single
endpoint that handles all the operations – therefore it has to have an
application-specific interface.
2. A REST ful service has a number of resources (the collection, each
entry), so the operations can be distributed onto the resources and
mapped to a small uniform set of operations.
28. What are the advantages of using Soft Layer's REST
API?
1. Direct client to server communication is the biggest
advantage of using REST.
2. With REST you can directly link to the information
that you want to display, using XLST or JavaScript to
display it.
3. You can also use AJAX with JSONP or script
injection to dynamically update your webpage.
29. What are the disadvantages of using a REST API?
1. REST requests must contain all
information, including authentication, within
the URL.
2. This can lead to security threats somewhere down
the line. Luckily, Soft Layer allows you to add any
number of users to your account, and then restrict
their access to specific servers/services.
30. • Resources and Resource Identifiers
• Uniform Interface (GET, PUT, POST, DELETE)
• Resource Oriented
• Simple and simple is beautiful
HTTP Method CRUD Desc.
POST CREATE Create -
GET RETRIEVE Retrieve Safe, Idempotent,
Cacheable
PUT UPDATE Update Idempotent
DELETE DELETE Delete Idempotent
31. Rest Data Element (cont.)
• safe : no side effect, The word "safe" means that if a given
HTTP method is invoked, the resource state on the server
remains unchanged
• The word "idempotent" means that, regardless of how many
times a given method is invoked, the end result is the same.
• GET is always safe. No matter how many times you download
this web page, the contents of it will not change due to your
repeated downloads, since you cannot change the web page
in that way.
32. 1. All replies to queries are expressed as JSON objects.
2. The general form, which all query replies share, is an array of arrays.
3. The inner array contains a map with two elements: command and
reply.
4. “command” is that portion of the query which is being responded to
with this entry;
5. “reply” is the query contents in response to the command portion.
For example, the response to …/fetch?shelf=48 would be a
configuration of shelf 48 encoded as a JSON stream as follows:
[[{"command":"shelf=48"}, {"reply":[{"numberOfPools":3,"totalPoolStorage":3
000633,"percentPoolStorageAllocated":20,"numberOfLvs":7,"numberOfSnaps
hots":129,"type":"VSX3500","eladdr":"5100002590357054","model":"VSX3500-
G6","release":"VSX-1.3.5","origRelease":"VSX-
1.3.5","serial":"CVS3500G60A000000000057","numAvailDisks":0,"uptime":"19
days 19:43:39","idPath":"shelf=48"}]}]]