2. REST, ROA, and Web Services
Architectural style of the WWW
One way to build RESTful
web services
Not very well defined
REST:
ROA:
Web Services:
3. So what is “Web Services”?
...hem hem haw hem haw...
What they said
<shrug/> Here's some software.
They're great! Buy our tools!
W3C:
Wikipedia:
Apache:
Microsoft:
4. So what is “Web Services”??
Software services deployed on the WWW
intended for use by other software components
5. What is REST?
Architectural style for distributed hypermedia systems
Behind the architecture of the WWW
Described in “Architectural Styles and the Design of
Network-based Software Architectures” by Roy T.
Fielding
6. Software Architecture
A set of rules about the components, connectors,
and data in a software system intended to induce
some desired properties.
“...A software architecture is an abstraction of the run-time
elements of a software system during some phase of its
operation.”
--Roy T. Fielding
7. Architectural Style
“a set of rules that an architecture should
conform to”
-- from the RestWiki
“...a coordinated set of architectural constraints that restricts
the roles/features of architectural elements and the allowed
relationships among those elements within any architecture that
conforms to that style.”
-- Roy T. Fielding
15. What does it buy me?
Large surface area
Scalable and Reliable
Easy to use and Robust
Transparent and Reliable
Addressable =
Stateless =
Connected =
Uniform =
16. Where REST came from
CERN – ENQUIRE project
MOMSpider and libwww-perl
mailing list for NCSA httpd becomes
the Apache HTTPD Project
REST guides the architecture of the
WWW, and the WWW serves as a
testbed for the ideas behind REST
1990-1992:
1993-1994:
1994-1995:
1995-now:
21. HTTP Methods
Retrieve a resource
Retrieve resource metadata
Determine the methods supported by
a resource
Create or update a resource
Destroy a resource
Create a new subordinate resource
GET
HEAD
OPTIONS
PUT
DELETE
POST
24. HTTP Response Codes
A set of standardized codes that describe the
outcome of an HTTP request.
100-199: Informational
200-299: Success
300-399: Redirection
400-499: Client error
500-599: Server error
25. HTTP Headers
Metadata about an HTTP request or response.
Some headers are control metadata, while others
are resource metadata.
26. Resource Oriented Architecture
“...a set of concrete rules for building web services that really
will be RESTful”
--Richardson and Ruby, “RESTful Web Services”
29. ROA Oversimplified
1. Figure out the data set
2. Split the data into resources
For each kind of resource:
3. Name the resources with URIs
4. Expose a subset of the uniform interface
5. Design the representation(s) accepted from the client
6. Design the representation(s) served to the client
7. Integrate this resource into the others, using links and forms
8. What's supposed to happen?
9. What might go wrong?
Adapted from “RESTful Web Services”, by Richardson and Ruby
34. 1. Figure out the data set
a menu of pizzas, sides, and toppings which have a
photo, a price, and a description
a special has a discounted price for one or more menu
items, and will expire.
an order has a creation time, a total price, a delivery
address, a status, and one or more menu items
35. 2. Split the data set into resources
a menu
a pizza, identified by name
a side, identified by name
the list of available pizza toppings
a topping, identified by name
the list of current specials
a special
an order
36. 3. Name the resources with URIs
the menu: http://www.decentpizza.com/menu
a pizza: http://www.decentpizza.com/menu/pizza/{name}
a side: http://www.decentpizza.com/menu/side/{name}
the list of toppings:
http://www.decentpizza.com/menu/toppings
a topping: http://www.decentpizza.com/menu/topping/
{name}
the list of current specials:
http://www.decentpizza.com/menu/specials
a special: http://www.decentpizza.com/menu/special/
{id}
an order: http://www.decentpizza.com/orders/{id}
37. 4. Expose a subset of the uniform interface
For the menu and below: GET, HEAD, and OPTIONS
To place an order: POST
http://www.decentpizza.com/orders
To check order status: GET
http://www.decentpizza.com/orders/{id}
To cancel an order: DELETE
http://www.decentpizza.com/orders/{id}
38. 5. Design the representation(s) accepted
from the client
Placing an order:
39. 6. Design the representation(s) served to
the client
The menu:
40. 6. Design the representation(s) served to
the client
An order:
41. 7. Integrate this resource with other
resources using links and forms
When the client GETs an order, it includes a form that
describes how to cancel it:
42. 8. What's supposed to happen?
For the menu and below: GET, HEAD, and OPTIONS
Response Code: 200 (OK)
POST http://www.decentpizza.com/orders :
Response Code: 201 (Created)
Location: http://www.decentpizza.com/orders/{new id}
GET http://www.decentpizza.com/orders/{id}:
Response Code: 200 (OK)
DELETE http://www.decentpizza.com/orders/{id}:
Response Code: 200 (OK)
43. 9. What might go wrong?
The client may try to access a menu item or
special that doesn't exist, like
/menu/drinks/margarita
404 (“Not Found”)
44. 9. What might go wrong?
The client might try to cancel an order that's
already been cancelled
404 (“Not Found”)
45. 9. What might go wrong?
The client might POST an order that my service
doesn't understand
400 (“Bad Request”)
46. 9. What might go wrong?
My ordering back end might be down
500 (“Internal Server Error”)
47. Where to learn more
The RestWiki
Roy T. Fielding's dissertation
RESTful Web Services (book)
The World Wide Web (surprised?)
Editor's Notes
1. (W3C paraphrased) Programmatic interfaces made available for application to application communication on the World Wide Web
2. (W3C quote) Web services provide a standard means of interoperating between different software applications, running on a variety of platforms and/or frameworks.
3. (Wikipedia paraphrased) clients and servers that communicate using XML messages that follow the SOAP standard, optionally using WSDL to describe interfaces.
4. xml.com quoting IBM: self-contained, self-describing, modular applications that can be published, located, and invoked across the Web.
5. RestWiki: distributed computing using web standards wherein the data being exchanged is designed for machine consumption rather than human consumption.
“Big Web Services” include SOAP, WSDL, WS-*
“The intended conceptual target of a hypertext reference”
-- Roy T. Fielding
Any useful information about a resource&apos;s current state.
Guides the client in changing resource or application state.
Addressable: Everything interesting about your service is immediately accessible from the outside
Stateless: Load balancing, retries, caching
Connected: Easy to figure out what it does and how to use it. Even when you change those things.
Uniform Interface: Easy to figure out again, and also allows intermediaries to understand each request at a deeper level. Reduces coupling between components.
“REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems.” -- Fielding
Also, supports gradual and fragmented deployment of changes within an already deployed architecture.
The World Wide Web began as a CERN project called ENQUIRE, initiated by Tim Berners-Lee and Robert Cailliau in 1990. Berners-Lee and Cailliau were jointly honored by the ACM in 1995 for their contributions to the development of the World-Wide Web.
Filesystem example component
Contrast this with the architectural “process” used to automatically generate a SOAP-based web service and WSDL from java or .NET code.
This is much more work for you. But it reduces work for each of your service consumers. And you get the benefits of uniform interface, addressability, statelessness, and connectedness.