Sunday, 3 May 2009

Is EXPRESS RESTful

For a system to be RESTful it must adhere to constraints of having a uniform interface and using hypertext as the engine of the application state. In the light of these constraints we will describe how EXPRESS is RESTful, first by showing how it has a uniform interface, then by discussing how it can use hypertext to change states. The examples explained are from EXPRESS.
According to Fielding having a uniform interface means: “having a unique resource identifier mechanism, having access methods with the same semantics for all resources, resources are manipulated by exchanging representations and messages for actions and representations are self descriptive.”[1]
In EXPRESS a resource is a class, an instance or a property, each one of them has a URI. And the access methods that can be applied are (OPTIONS, GET, PUT, DELETE and POST). Having the same semantics with the relation to resources we can realize a pattern illustrated in the following table

Resource

OPTIONS

Semantics

Class in an ontology

GET

Gets the structure of the class

POST

A factory endpoint to create instances of this class

Instance or property

GET {only}

Read only instance or property

Instance or property

GET, PUT, DELETE

Modifiable instance or property



But taking this to a higher level of semantics, does the system respond internally to posting an order in the same way it responds to posting a customer? Then the answer is no. And we believe it is still RESTful because the semantics here are inferred from the shared understanding of the ontology, or in RESTful terms, the representations.
As for manipulation of resources by exchanging representations, this is done in EXPRESS. For example to modify a customer a representation of the customer in OWL or RDF is PUT to the customer’s URI. And messages are self-descriptive in the sense that they contain the method and the representation. The representation whether it is OWL or RDF is inherently self-describing.
For the other constraint of REST which is hypertext as the engine of the application state. Fielding describes it as: “each response contains a partial representation of server-side state, some representations contain directions on how to transition to the next state and that each steady-state (page) embodies the current application state.”
For an example of the response containing part of the application state, invoking GET on a resource returns a representation of that resource, which is part of the application state. Another example is when invoking POST on a URI representing a class, a generated URI of an instance of that class is returned, which is part of the application state (a new instance/resource is created). However when invoking a PUT on an instance to modify the resource, the message sent by the client contains the modified resource but the response -in EXPRSS- from the server doesn’t. This can be modified easily to make the server respond by sending a representation of the modified instance if the modification is accepted. But the question is, is that a requirement of REST? Is what Fielding means by the response: a response by either the server or the client and in that case EXPRESS is already RESTful, or does he mean that all responses from the server must contain part of the application-state? Another question is what is the impact of this constraint? Answering this question may guide us to the answer of the previous one.
Regarding the other statement, “some representations contain directions on how to transition to the next state”, this can be accomplished through the OWL file, since it states what the client can do with the resources. Another example is when a client wants to create a new resource, it POSTs to a class’s URI, a new generated URI for an instance of that class is sent back to the client, the client can use that URI to move to the other state which is PUTting the instance’s content to it.
For the last statement “each steady-state (page) embodies the current application state”, I am not quite sure how that works, it may be that the representation the server sends to the client contains the current application state.

I believe the picture right now is still quite vague; going into implementation may clarify it more.

[1] Roy T. Fielding, A Little REST and Relaxation, JAZOON’07 The international Conference on Java Technology, 24-28 June, 2007, Zurich.
http://www.parleys.com/display/PARLEYS/A+little+REST+and+Relaxation

Thursday, 16 April 2009

Understanding REST

I’ve been reading to answer the questions in my last post, and the picture is a bit clearer.

I think I now understand what we gain by HATEOAS. Instead of the client guessing where to go throughout an application by constructing URIs, it is guided by the server by providing it with hyperlinks (representations) to follow.

What do we gain from that?
More decoupling, thus more reusability, less likeliness of clients to break.

So that is HATEOAS, but what is statelessness.

The application state is on the client, because the client is keeping track of where it is and what it is doing. The server doesn’t need to do that.
In the book RESTful Web Services the authors differentiate between two types of states application state and resource state. Resource state is on the server and application state is on the client.

So in my case of ordering a pizza, should the order be a resource created by the client on the server, therefore a resource state? Or should it be part of the application state and should be stored on the client side?

There are some things to note here:
-In my pizza delivery there would be another client interested in the resource, the carrier service so having the order on the client that would not be very efficient.

-Scalability issues, having the order on the server won’t be as scalable and reliable as having the order on the client. In the RESTful Web Services book the authors wrote, “When your application is stateless you don’t need to coordinate activities between servers, sharing memory or creating “server affinity” to make sure the same server handles every request in a session you can throw web servers at the problem until the bottleneck becomes access to your resource state. Then you have to get into database replication, mirroring or whatever strategy is most appropriate for the way you have chosen to store your resource state”. My problem with that is that mostly what clients would deal with in Web Services are resource states, or are we thinking about resources in a wrong way.

-I believe the problem boils down to who creates resources in the book the clients could create resources, however in the dissertation, to the best I know Fielding didn’t mention that clients could create resources on the server. He referred to creators of resources as authors which I assume have control over the server. So if the client can create resources on the server, then the server is storing part of the application state which according to what I understood from Fielding's dissertation isn't RESTful.

-Also in the dissertation there is an example of a shopping cart “A state mechanism that involves preferences can be more efficiently implemented using judicious use of context-setting URI rather than cookies, where judicious means one URI per state rather than an unbounded number of URI due to the embedding of a user-id. Likewise, the use of cookies to identify a user-specific “shopping basket” within a server-side database could be more efficiently implemented by defining the semantics of shopping items within the hypermedia data formats, allowing the user agent to select and store those items within their own client-side shopping basket, complete with a URI to be used for check-out when the client is ready to purchase.” I think that if this was implemented using the RESTful Web Services book way then a client would create a shopping cart at the server then post items to it which won’t be as scalable as Fielding’s client side shopping basket.

Difference between REST and ROA
By REST I am referring to Fielding’s dissertation, and by ROA I am referring to the RESTful Web Services book.
-In REST there is no CRUD. It states that a uniform interface should exist but not what it is.
-In REST there is more emphasis on HATEOAS.
-In ROA there is more emphasis on uniform interface: GET, PUT, POST and DELETE.
-ROA uses the HTTP protocol and its methods to implement RESTful Web Services. In REST a set of constraints are set but not tied to any protocol or system.
-Web Services are not mentioned in REST, but they are the heart of ROA.

Limitations of REST
As stated by Fielding in his dissertation:
“The REST interface is designed to be efficient for large grain hypermedia data transfer, optimizing for the common case of the Web, but resulting in an interface that is not optimal for other forms of architectural interaction.”
“not optimal for other forms of architectural interaction” so why the fuss about RESTful Web Services? They are not transferring large grain hypermedia? Is it that the WS community saw in REST what Fielding didn’t see?

Another limitation which was pointed out by “Triple Space Computing” researchers when considering REST as an infrastructure is that there isn’t a way for the server to send notifications to clients asynchronously.