REST - A Super Quick Intro

2,843 views
2,720 views

Published on

A super-quick and high-level introduction to the principles of REST, prepared for the AusPost SAP development team

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,843
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
66
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

REST - A Super Quick Intro

  1. 1. REST<br />A Super-Quick Introduction<br />
  2. 2. REpresentationalStateTransfer<br />
  3. 3. Say What???<br />
  4. 4. Apply ‘Web’ Principles to A2A Integration Problems<br />
  5. 5. Remember the OSI Stack?<br />http://en.wikipedia.org/wiki/Osi_stack<br />
  6. 6. So what?<br />
  7. 7. REST uses HTTP as the Application Protocol!<br />Not (just) as the transport<br />
  8. 8. How does that work?<br />
  9. 9. Standard Verbs<br />The HTTP Spec give you the verbs to use:<br />GET<br />PUT<br />POST<br />DELETE<br />HEAD<br />OPTIONS<br />PATCH<br />TRACE<br />http://en.wikipedia.org/wiki/HTTP#Request_methods<br />
  10. 10. SOAP Doesn’t…<br />getAccountCustomerByInternalId<br />searchCustomerByBasicData<br />updateSalesProspectStatusByPartnerSalesRepresentativeBasicData_sync<br />Everything works via HTTP POST<br />(i.e. uses HTTP as the dumb transport)<br />
  11. 11. Status Codes<br />The HTTP Spec give you the verbs to use:<br />200 OK<br />302 Moved Permanently<br />404 Not Found<br />406 Method Not Allowed<br />418 I’m a Teapot<br />…<br />http://en.wikipedia.org/wiki/List_of_HTTP_status_codes<br />
  12. 12. SOAP Doesn’t…<br /><SOAP-ENV:Faultxmlns:sqlsoapfaultcode="http://schemas.microsoft.com/sqlserver/2004/SOAP/SqlSoapFaultCode"><br /> <faultcode>SOAP-ENV:Client</faultcode><br /> <faultstring>There was an error in the incoming SOAP request packet: Client, InvalidXml</faultstring><br /> <faultactor>http://schemas.microsoft.com/sqlserver/2004/SOAP</faultactor><br /> <detail xmlns:SOAP-1_2-ENV="http://www.w3.org/2003/05/soap-envelope"><br /> <SOAP-1_2-ENV:Code><br /> <SOAP-1_2-ENV:Value>SOAP-1_2-ENV:Sender</SOAP-1_2-ENV:Value><br /> <SOAP-1_2-ENV:Subcode><br /> <SOAP-1_2-ENV:Value>sqlsoapfaultcode:InvalidXml</SOAP-1_2-ENV:Value><br /> </SOAP-1_2-ENV:Subcode><br /> </SOAP-1_2-ENV:Code><br /> <SOAP-1_2-ENV:Reason><br /> <SOAP-1_2-ENV:Text xml:lang="en-US">There was an error in the incoming SOAP request packet: Sender, InvalidXml</SOAP-1_2-ENV:Text><br /> </SOAP-1_2-ENV:Reason><br /> <SOAP-1_2-ENV:Node>http://MyServer:80/sql</SOAP-1_2-ENV:Node><br /> <SOAP-1_2-ENV:Role>http://schemas.microsoft.com/sqlserver/2004/SOAP</SOAP-1_2-ENV:Role><br /> <SOAP-1_2-ENV:Detail><br /> <sqlresultstream:SqlMessagexsi:type="sqlmessage:SqlMessage"><br /> <sqlmessage:Class>16</sqlmessage:Class><br /> <sqlmessage:LineNumber>0</sqlmessage:LineNumber><br /> <sqlmessage:Message>XML parsing: line 3, character 0, incorrect document syntax</sqlmessage:Message><br /> <sqlmessage:Number>9422</sqlmessage:Number><br /> <sqlmessage:Source>Microsoft-SQL/9.0</sqlmessage:Source><br /> <sqlmessage:State>1</sqlmessage:State><br /> </sqlresultstream:SqlMessage><br /> </SOAP-1_2-ENV:Detail><br /> </detail><br /></SOAP-ENV:Fault><br />
  13. 13. So What’s Wrong with that?<br />
  14. 14. So What’s Wrong with that?<br />Suboptimal<br />
  15. 15. Scalability<br />HTTP GET is the most optimised piece of code on the planet!<br />Easily cached to support millions of clients<br />Defined semanticsHTTP = Application Protocol<br />Everyone knows how to do a GET<br />Everyone knows how to behave<br />
  16. 16. We Exchange Representations<br />
  17. 17. Representations?<br />The server can store its data/objects in whatever way it likes<br />The clients can store the same stuff differently<br />We serialise that into Representations<br />
  18. 18. Less Abstract…<br />A Website is a Representation of the server’s database, code, etc.<br />Clients don’t care how the server stores it, as long as it understands the Representation<br />
  19. 19. State Transfer?<br />
  20. 20. State is Transferred between Server and Client<br />Not just kept at the Server!<br />
  21. 21. Client requests Shopping Cart<br />Server sends HTML page with items and links<br />Client’s move<br />Client clicks “Check Out”<br />Server sends HTML page with Total Amount<br />Client’s move<br />Client clicks “Pay”<br />Server sends HTML page with “Thank You”<br />and we’re done!<br />
  22. 22. Notice Something?<br />
  23. 23. The Client Drives the Interaction<br />Responsible for moving forward<br />Or not!<br />The server guides the client forward<br />(with ‘Check Out’, ‘Pay’ links)<br />The client is responsible for completing the process<br />If the client stops, the server doesn’t care!<br />
  24. 24. And…<br />
  25. 25. Everything has a URL<br />
  26. 26. So it’s like the Web!<br />…Just for Machines<br />
  27. 27. Restbucks<br />works with whisky too ;-)<br />http://www.infoq.com/articles/webber-rest-workflow<br />
  28. 28. So, the Formal Principles:<br />
  29. 29. REST Principles<br />Identify Resources (URLs)<br />Manipulate Resources through Representations<br />Self-Descriptive Messages<br />HATEOAS<br />http://www.infoq.com/articles/rest-introduction<br />
  30. 30. HypertextAsTheEngineOfApplicationState<br />
  31. 31. In other words:<br />Linking Things TogetherDriving the Process via Links<br />Like the ‘Check Out’ link!<br />
  32. 32. …and some Constraints:<br />Client-Server<br />Stateless<br />Cacheable<br />Layered System<br />Uniform Interface<br />Duh!<br />= scalable<br />= scalable<br />load balancers, proxies<br />HTTP verbs & codes<br />
  33. 33. Finally:<br />http://geekandpoke.typepad.com/geekandpoke/2009/11/service-calling-made-easy-part-1.html<br />
  34. 34.
  35. 35. More Resources:<br />http://en.wikipedia.org/wiki/REST<br />http://www.infoq.com/rest<br />http://www.infoq.com/articles/webber-rest-workflow<br />http://www.infoq.com/minibooks/emag-03-2010-rest (Excellent FREE eBook)<br />CD108 from 2010 TechEd<br />https://www.ibm.com/developerworks/webservices/library/ws-restful/<br />

×