Presentation is loading. Please wait.

Presentation is loading. Please wait.

Representational State Transfer (REST) Paul Townend 8 th February 2007.

Similar presentations

Presentation on theme: "Representational State Transfer (REST) Paul Townend 8 th February 2007."— Presentation transcript:

1 Representational State Transfer (REST) Paul Townend 8 th February 2007

2 What is REST? (I) REST is an architectural style for distributed hypermedia systems. REpresentational State Transfer. The term originated in a year 2000 PhD thesis by Roy Fielding. REST states that the existing principles and protocols of the web are enough to create robust Web Services – you dont need SOAP.

3 What does it consist of? (I) REST is a very simple architecture: Application state and functionality is divided into resources. Every resource is uniquely addressable using a universal syntax for use in hypermedia links. All resources share a uniform interface for the transfer of state between a client and a resource.

4 What does it consist of? (II) The uniform interface features a constrained set of well-defined operations and a constrained set of content types. REST uses a protocol that is client/server, stateless, cacheable and layered. The REST methodology is identical to the way in which a Web browser gets Web pages from or posts to a web server. An example...

5 In practice... (I) A web page is a resource. So is a jpeg picture file located on that web page. So are any links, sound files, etc. Resources are accessible using a universal syntax – the URI. With REST, URIs are assigned to individual data records, customer records, and orders, as transferred between a Web Service and a Client.

6 In practice... (II) The well-defined operations supported by REST resources are simply HTTP verbs, the most important of which are GET, POST, PUT and DELETE. These operations are used to issue a request to a REST Web Service to access and manipulate the server-side state, or data record, identified by the URI.

7 In practice... (III) These verbs can be seen as being similar to the cut and paste paradigm, and also to the CRUD operations associated with DBMS. GET = READ or COPY PUT = UPDATE or PASTE OVER POST = CREATE or PASTE AFTER DELETE = DELETE or CUT

8 REST Nouns (unconstrained) e.g. Verbs (constrained) e.g. GET Content types (constrained) e.g. HTML The REST triangle REST is not a standard – its an architectural style, although it does prescribe the use of standards (HTTP, URI, XML/HTML/JPEG etc)

9 An example

10 An example (I) Ill now show an example of a RESTful service – this is stolen from Consider a Parts Depot Web Service, which allows its customers to: Get a list of parts Get detailed information about a particular part Submit a purchase order (PO)

11 An example (II)

12 An example (III) Get a list of parts A RESTful web service makes a URI available to its parts list resource. So youd access something like: If the service wishes to specify what type of document the user wants…

13 An example (IV)

14 An example (V) Get information about a particular part The RESTful Web Service makes available a URI to each part resource, such as: This is a logical URI – it expresses what resource is desired. It is not a physical object. You dont need a million HTML pages if you have a million parts.

15 An example (VI)

16 An example (VII)

17 Reiteration As can be seen from the example, RESTful services feature: Client/Server interaction style Stateless requests Cache: responses can be marked cacheable or otherwise Uniform interface: GET, POST, etc. Named resources: URIs Interconnected resource representations

18 Claimed Benefits (I) Advocates of REST claim: Provides improved response times due to support for caching Improves server scalability by reducing the need to maintain communication state (i.e. different servers can handle initial and subsequent requests). Depends less on vendor software than mechanisms that layer additional messaging frameworks on top of HTTP (such as SOAP)

19 Claimed Benefits (II) Provides equivalent functionality when compared to alternative approaches to communication Does not require a separate resource discovery mechanism due to use of hyperlinks in content. Provides better long term compatibility and evolvability characteristics than RPC: capability of document types like HTML to evolve without breaking backwards or forwards compatibility Ability of resources to add support for new content types as they are defined without dropping or reducing support for older content types

20 Parts Depot with SOAP

21 REST / SOAP (I) SOAP and REST are essentially the same in what they do, but different in how they work. Both methods allow programs to exchange XML messages over a network. I shall now detail some differences…

22 REST / SOAP (II) A SOAP server must look inside a SOAP envelope to find the target resource. With REST, all decisions are based on the URI and HTTP method. If an organisation has a proxy server (or gateway, cache, etc.) that filters out certain URIs, a RESTful interaction can be analysed much more easily, whilst with SOAP the envelope would need to be inspected, and the proxy would have to understand the semantics of every SOAP application.

23 REST / SOAP (III) In a network-based application, communications are often a bottleneck. With REST, resources can be cached locally. Conversely, when submitting a SOAP message, HTTP POST is used, so a cache server will not know from the HTTP method whether a client is doing a request. Also, the SOAP URI is always the SOAP server. So no caching is possible with SOAP.

24 REST / SOAP (IV) REST is consistent with the vision of the semantic web (every resource has a logical URI). SOAP URIs are funneled through a single URI to the SOAP server – not consistent. REST has a generic interface; SOAP has no defined set of methods. Consequently, tools must be customised on a per-application basis with SOAP. This is not scalable.

25 REST / SOAP (V) In terms of interoperability, SOAP depends on much more customisation than REST. Each SOAP message provides a unique method of naming a resource, and each SOAP application defines its own interface. REST is based on standards: URIs, HTTP GET/POST/PUT/DELETE, HTML, XML, GIF, MIME, etc. So proponents argue that REST is more inherently interoperable.

26 REST / SOAP (VI) With both REST and SOAP applications, you need prior agreement on data semantics. However, if the payload is RDF or DAML, the client may be able to dynamically learn the meaning of the response data. With REST, there are links to the next state built into every link response; with dynamic learning of response data + dynamic reasoning of link traversals, self-reasoning automata may be possible!

27 Conclusions (I) REST is simple, and is also cost-effective and highly scalable. There is a big debate in the WS community about whether to use REST/SOAP. Amazon report that usage of their web services is 80% REST, and 20% SOAP. SOAP cannot be utilised by proxy serves, cache servers, etc.

28 Conclusions (II) Some argue that SOAP is best used only in closed systems. REST is growing in popularity primarily due to its ease of implementation. REST is considered to be faster than SOAP (Amazon claim that REST is up to six times faster)

29 Conclusions (III) I have heard arguments that REST is very attractive for basic applications that involve high levels of interoperability between multiple platforms. And SOAP is appropriate for larger, formal applications that require advanced capabilities between relatively homogenous systems. SOAP has rich functionality but at the expense of interoperability.

30 Final comparisons - REST REST Messages represented in plain XML HTTP used as transfer protocol HTTP verbs used for access/manipulation URIs are used to uniquely identify resources HTTP authentication used for security No formal method for expressing interface content

31 Final comparisons - SOAP SOAP Messages are represented in a standardised XML SOAP envelope. Can be bound to different protocols (i.e. HTTP, SMTP) Access/manipulation of data is application specific. Security is not described by SOAP and is to be provided by the developer. XML schemas used to define contract between the Client and the Service.

Download ppt "Representational State Transfer (REST) Paul Townend 8 th February 2007."

Similar presentations

Ads by Google