I’ve started work on a pre existing REST application and am having trouble understanding how one would go about making a RESTful client?
The page on wikipedia states the following
“Clients make state transitions only through actions that are dynamically identified within hypermedia by the server (e.g. by hyperlinks within hypertext). Except for simple fixed entry points to the application, a client does not assume that any particular actions will be available for any particular resources beyond those described in representations previously received from the server.”
If all the client can assume is a starting url then apart from a pure HTTP rest service running in a browser how would it be possible for the client to know how to display any information returned.
For example a java/flash client would have to make an assumption about what data is returned in order to know how to display it, ad then of course the implementation would cease to be restful??
Thanks for any insight.
Piers
There is a difference between state transitions and telling the client how to display the information. In HTTP the data type is usually determined by the
Content-Typeheader field based on which the client decides on how to display it (e.g. a browser would requesttext/htmland render the result). REST does not make the assumption that the data are self describing, just that they should be semantically connected through URIs. What the wiki page states is that if you are requestingapplication/jsonathttp://example.comit will return something like this:Now you know what URI to request to get a list of todos and a request to
http://example.com/todosmight return something like this:Instead of just returning an id, the user key references the actual URI for the connected user resource, so you can directly request it.