5-Minute Introduction To REST: Roger L. Costello Timothy D. Kehoe
5-Minute Introduction To REST: Roger L. Costello Timothy D. Kehoe
Roger L. Costello
Timothy D. Kehoe
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
2
What is REST?
• REST is a design pattern.
• It is a certain approach to creating Web
Services.
• To understand the REST design pattern,
let's look at an example (learn by example).
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
3
Example:
Airline Reservation Service
• 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...
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
4
Approach 1
"Press 1 for Premier, Press 2 for…"
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
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
5
Approach 2
Telephone Numbers are Cheap! Use Them!
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
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
6
Discussion
• In Approach 1 the answering machine
introduces an extra delay, which is particularly
annoying to premier members. (Doesn't
everyone hate those answering systems)
• With Approach 2 there is no intermediate step.
Premier members get instant pickup from a
customer service representative. Others may
have to wait for an operator.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
7
Approach 1
One-Stop Shopping
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
client
Regular Members
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
9
Approach 1 Disadvantages
• 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.
• The Web service is a central point of failure. It is a
bottleneck. Load balancing is a challenge.
• It violates Tim Berners-Lee Web Design, Axiom 0 (see
next slide).
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
10
URL2 resource2
URL3 resource3
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
Approach 2:
11
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
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
12
Approach 2 Advantages
• 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.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
13
Recap
• 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.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
14
Regular
Customer
Representative
Regular Members
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
15
This is the
REST Design Pattern
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
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
16
client
Regular Members
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
This is the
17
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
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved.
18
Resources