 
              Introduction to REST Web Services 2/14/2009 Agenda  What is REST? Introduction to REST Web  REST Web Services Characteristics Services  Principle of REST Web Services Design  Semantic of HTTP/1.1 Operations Asst. Prof. Dr. Kanda Runapongsa Saikaew  Assets and Drawbacks (krunapon@kku.ac.th) Department of Computer Engineering  Security Khon Kaen University  REST vs. SOAP 1 2 What is REST? Why Representational State Transfer? (1/2)  REST is a term proposed by Roy  The Web is comprised of resources Fielding in his Ph.D. dissertation  A resource is any item of interest  REST is to describe an archit itecture ecture http://gear.kku.ac.th/~krunapon styl yle of networked systems  A representation of the resource is  REST is an acronym standing for returned Representational State Transfer  The representation places the client application in a state 3 4 Roy Fielding‟s Explanation Why Representational State Transfer? (2/2)  The result of the client traversing a  Representational State Transfer is intended to evoke an image of how a well- hyperlink results in another resource designed Web application behaves: a is accessed network of web pages (a virtual state  The new representation places the machine), where the user progresses client application into yet another through an application by selecting links state (state transitions), resulting in the next page (representing the next state of the  The client application changes application) being transferred to the user (transfers) state with each resource and rendered for their use.” representation  Representational State Transfer! 5 6 Dr. Kanda Runapongsa Saikaew, Computer Engineering, Khon Kaen University 1
Introduction to REST Web Services 2/14/2009 REST Uses These Standards REST, An Architectural Style, Not a Standard  REST is not a standard  HTTP  You will not see the W3C putting out a  URL REST specification  XML/HTML/GIF/JPEG/etc  REST is just an architectural style (Resource Representations)  You can only understand the style  text/xml, text/html, image/gif, and design your Web services in that image/jpeg, etc (Resource Types, style MIME Types)  Analogous to the client-server architectural style, there is no client- server standard 7 8 The Classic REST System Parts Depot Web Services  The Web is a REST system  Parts Depot has deployed some web services to enable its  Many of those Web services that you have been using these many years customers to  Book-ordering services  Get a list of parts  Search services  Get detailed information about a  Online dictionary services particular part  REST is concerned with the “big  Submit a purchase order picture” of the Web  It does not deal with implementation details 9 10 Get Parts List The Client will Receive  The web service makes available a <?xml version=“ 1.0 ”?> <p:Parts xmlns:p=„http://www.parts - depot.com‟ URL to a parts list resource xmlns:xlink=„http://www.w 3.org/1999 /xlink‟>  For example, a client would use this <Part id=„ 00345 ‟ xlink:href=„http://www.parts - depot.com/parts/00345 ‟/> URL to get the parts list <Part id=„ 00346 ‟ xlink:href=„http://www.parts -  http://www.parts-depot.com/parts depot.com/parts/00346 ‟/> </p:Parts>  Parts Depot is free to modify the  The parts has links to get detailed info about each part underlying implementation of this  The client transfers from one state to the next by resource without impacting clients examining and choosing from among the alternative URLs in the response document. (loose coupling) 11 12 Dr. Kanda Runapongsa Saikaew, Computer Engineering, Khon Kaen University 2
Introduction to REST Web Services 2/14/2009 Get Detailed Part Data The Client will Receive <?xml version=“ 1.0 ”?>  The web service makes available a <p:Part xmlns:p= „http://www.parts -depot.com ‟ URL to each part resource xmlns:xlink=„http://www.w 3.org/1999 /xlink‟>  For example, here‟s how a client <Part-ID>00345</Part-ID> requests part 00345: <Name>Widget-A</Name>  http://www.parts-depot.com/parts/00345 <Description>This part is used within the frap assembly</Description> … <Quantity>10</Quantity> </p:Part> 13 14 Agenda REST Web Services Characteristics (1/3)  What is REST?  Client-server  A pull-based interaction style:  REST Web Services Characteristics consuming components pull  Principle of REST Web Services representations Design  Stateless  SOAP vs. REST Style  Each request from client to server must  REST Assets and Drawbacks contain all the information necessary to understand the request  Security with REST  Cannot take advantage of any stored  Public Web Services text on the server 15 16 REST Web Services Characteristics (2/3) REST Web Services Characteristics (3/3)  Cache  Interconnected resource  To improve network efficiency, responses representations must be capable of being labeled as  The representations of the resources cacheable or non-cacheable are interconnected using URLs, thereby  Uniform interface enabling a client to progress from one  All resources are accessed with a generic state to another interface (e.g., HTTP GET, POST, PUT,  Layered components DELETE)  Named resources  Intermediaries, such as proxy servers, cache servers, gateways, etc, can be  The system is comprised of resources which inserted between clients and resources are named using a URL to support performance, security, etc. 17 18 Dr. Kanda Runapongsa Saikaew, Computer Engineering, Khon Kaen University 3
Introduction to REST Web Services 2/14/2009 Agenda Principles of REST Web Service Design (1/4)  What is REST?  The key to creating Web services in a REST network (i.e., the Web)  REST Web Services Characteristics is to identify all of the conceptual  Principle of REST Web Services entities that you wish to expose Design as services  Semantic of HTTP/1.1 Operations  Assets and Drawbacks  Above we saw some examples of resources: parts list, detailed part  Security data, purchase order  REST vs. SOAP 19 20 Principles of REST Web Service Design (2/4) Principles of REST Web Service Design (3/4)  Create a URL to each resource. The  Categorize your resources according to resources should be nouns, not verbs whether clients can just receive a representation of the resource or whether  For example, do not use this clients can modify (add to) the resource  http://www.parts-  All resources accessible via HTTP GET depot.com/parts/getPart?id=00345 should be side-effect free  Note the verb, getPart Instead, use a  No man/woman is an island noun  Put hyperlinks within resource  http://www.parts-depot.com/parts/00345 representation to enable clients to drill down for more information 21 22 Agenda Principles of REST Web Service Design (4/4)  Design to reveal data gradually  What is REST?  Don‟t reveal everything in a single response  REST Web Services Characteristics document  Principle of REST Web Services  Provide hyperlinks to obtain more details Design  Specify the format of response data using a schema (DTD, W3C Schema)  Semantic of HTTP/1.1 Operations  Describe how your services are to be  Assets and Drawbacks invoked using either a WSDL document or  Security simply an HTML document  REST vs. SOAP 23 24 Dr. Kanda Runapongsa Saikaew, Computer Engineering, Khon Kaen University 4
Introduction to REST Web Services 2/14/2009 Semantic of HTTP/1.1 Operations (1/3) Semantic of HTTP/1.1 Operations (2/3)  GET  POST  “Retrieve whatever information (in the  “Request that the origin server accept form of an entity) is identified by the the entity enclosed in the request as a Request- URI” new subordinate of the resource identified by the Request- URI”  Retrieve representation, shouldn‟t result in data modification  Annotation of existing resources, extending a database through an append operation  Posting a message to a bulletin board, or group of articles  Providing a block of data (e.g., form data) to a data-handling process 25 26 Agenda Semantic of HTTP/1.1 Operations (3/3)  PUT  What is REST?  “Requests that the enclosed entity be  REST Web Services Characteristics stored under the supplied Request- URI”,  Principle of REST Web Services create/put a new resource Design  DELETE  Semantic of HTTP/1.1 Operations  “Requests that the origin server deletes  Assets and Drawbacks the resource identified by the Request- URI”  Security  REST vs. SOAP 27 28 REST Assets REST Drawbacks  Development and testing without complex  Restrictions for GET length toolkits sometimes may be a problem  Debugging of REST requests with a web  No direct bridge to the OOP world browser  Difference between REST and RPC  Requires a HTTP client, available in every common language style may be subtle sometimes, but not  REST services can be easily used by AJAX necessarily in general case applications  APIs in REST style are more consumable than complex APIs  Lower learning curve for consumer  Everything accessible through universal API 29 30 Dr. Kanda Runapongsa Saikaew, Computer Engineering, Khon Kaen University 5
Recommend
More recommend