Restful Application Protocol
Babita Saini
Outline
• Introduction • What Is a Domain Application Protocol? • Design Steps • A RESTful Procurement Application • References Domain Application Protocol
• A domain application protocol is the set of rules and conventions that guides and constrains the interactions between participants in a distributed application. • By adhering to a protocol, participants achieve a useful domain or business outcome. Procurement
Request Quote Order Goods Confirm Order CUSTOMER SUPPLIER Cancel Pay
• The process implies the effective existence of a domain application protocol, a set of rules and conventions through which participants in a distributed system coordinate their interactions to achieve a useful, domain-specific application goal. Application, application protocol, application state
• An application is defined as the computerized behavior directed towards achieving a particular client or end user goal. A distributed application is one in which multiple participants employ computing behavior to realize an application goal. • Application state is a snapshot of the state of a distributed application at a particular point in time.
Application State in a RESTful Application • RESTful web application delegates the responsibility for remembering the overall state of an application to the client or clients participating in that application.
Client conversation is expensive, particularly at web scale.
• Client is presented with additional resources which Server encodes using links and forms(Hypermedia) Design Steps Three steps to design and implement Restful Web Services
• 1. Model applications as application protocol state machines. • 2. Implement them based on resources, resource life cycles and the server-governed rules that associate resources. • 3. Document and execute them using media types, link relations, and HTTP idioms. Step 1: It is concerned with the design of an abstract domain application protocol. Procurement applica on state transi ons By explicitly modeling a protocol as a state machine, we gain a better understanding of the “value stream” of application state transitions through which value is released both to the customer and to the organisation(s) owning a process.
Quote Goods Order Requested Ordered Confirmed
Paid Cancelled Step 2: Resource, Resource state • Resource : Defined as being a membership function, which groups a set of equivalent resource representations and identifiers. Membership of this set can vary over time. • For most resources, a resource’s state is simply a function of its data. For some resources,a resource’s state is also partly a function of the state of other resources with which the resource is associated through some server-governed rules. Operation oriented vs Resource Oriented
CreateQuote SearchOrders ReserveItem Operation Oriented SubmitQuote RemoveItem AddItem CancelOrder
Quote Order Item
• GET • GET • GET • PUT • PUT • PUT Resource Oriented • POST • POST • POST • DELETE • DELETE • DELETE CreateQuote SearchOrders CancelOrder SubmitQuote
GET PUT POST
DELETE
GET PUT POST
DELETE
Specialization and Innovation depends on an open set Hypermedia Systems change application state Ø A hypermedia system comprises a client, one or more server-governed resources, and some systemic behavior. This systemic behavior is initiated when a client makes a request of a resource – in a web application this will be a resource identified by a URI. Ø The resource responds with a representation of its resource state. This representation includes one or more hypermedia controls – links and forms – which advertise legitimate interactions with other resources. Ø The client processes the response and updates its understanding of the current state of the application. Ø If it hasn’t yet achieved its application goal, the client chooses the hypermedia control best suited to making forward progress, and operates that control. Ø Operating the control triggers another request, and the cycle begins again. Hypermedia Systems Transform Application State Step 3 Media types
• A RESTful API is documented using media types, link relations and HTTP idioms. • A media type value, such as application/atom+ xml, is a key into a data format. Hypermedia system implements: Ø The format to be used for representing content. Ø One or more schemas to which content must conform. Ø Hypermedia control formats. Ø Semantic annotations for hypermedia controls. Two Common Hypermedia Formats: XHTML and ATOM • Both are commonplace today • Both are hypermedia formats • – They contain links • Both have a processing model that explicitly supports links • Which means both can describe protocols… XHTML Default XML • XHTML is just HTML that is also XML namespace • For example: namespace
... XHTML in Action
Atom Syndication Format HTTP/1.1 200 OK • The application/atom + Content-Length: 342 xml media type is Content-Type: application/atom+xml Date: Sun, 22 Mar 2009 17:04:10 GMT hypermedia awareA RESTful Procurement Application It influences the behavior of any caching intermediaries Application Start – local caches, proxies, and reverse proxies – along the request–response path
Generalized, format for representing quotes and orders
Entry point resources LINK AND SEMANTIC CONTEXT Start
STARTED…. Get request--‐for--‐quote form Request XForms
XForms
Submit an order form Indicate order submitted successfully status code separates the action of accepting the request from the work necessary to fulfil it. Quote Requested to Goods Ordered Design Strategies Prefilled form Alternate representation of quote data, adapted for submitting an order
202 Accepted Long--‐running operations Successfully accepted request but result is not immediately available. Check state of order
Request GET /orders/9876 HTTP/1.1 Host: restbucks.com Response HTTP/1.1 404 Not Found Check state of order again Request GET /orders/9876 HTTP/1.1! Host: restbucks.com! Return order The order’s
Request GET https://example.org/payments/1010 HTTP/ 1.1 Return payment form
200 ok from awaiting state Submit payment details
Request POST https://example.org/payments/1010 HTTP/1.1 Content-Type: application/x-www-form urlencoded Content-Length: ... cardtype=Visa+Debit&name=MR+JOHN+SMITH! ➥&card-number=4876512418675010&security- code=212! Confirm Payment Notify Restbucks
Get order Request GET /orders/9876 HTTP/1.1! Host: restbucks.com! If-None-Match: "4d3e88c9"! Return Order Order confirmed to paid
References
• Rest in Practice by Jim Webber, Ian Robinson • http://dev.opera.com/ articles/view/http-basic- introduction/ • http://blog. 2partsmagic.com/restful-uri- design/