The various talks I have watched and tutorials I scanned on REST seem to stress something called ‘discoverability’. To my limited understanding, the term seems to mean that a client should be able to go to http://URL
– and automatically get a list of things it can do.
What I am having trouble understanding – is that ‘software clients’ are not human beings. They are just programs that do not have the intuitive knowledge to understand what exactly to do with the links provided. Only people can go to a website and make sense of the text and links presented and act on it.
So what is the point of discoverability, when the client code that accesses such discoverable URLs cannot actually do anything with it, unless the human developer of the client actually experiments with the resources presented? This looks like the exact same thing as defining the set of available functions in a Documentation manual, just from a different direction and actually involving more work for the developer. Why is this second approach of pre-defining what can be done in a document external to the actual REST resources, considered inferior?
The need for discoverability may not be relevant, but the links that allow discoverability serve more purposes. The most important of these, to my mind, is that providing full URI’s in the responses to the client, means that no client will ever need to “compose” an URI. That means that no client will ever need knowledge about how the URI’s are structured. And that in turn allows the server developers to change the URI scheme whenever it suits them as they do not need to consider older clients still relying on an old way of structuring URI’s.
4
“Clients” may not be advanced enough to make use of it, but the users of clients can. A client can be something as simple as a web browser, after all. The discoverability is all about enabling people to learn and use the API.
For example, Jenkins (the CI server) has a REST-like interface. Go to any page, postfix the URL with “/api”, and you get a page describing everything you can do. It makes learning the API trivial. For example, http://ci.jruby.org takes you to the jenkins server for jruby, and http://ci.jruby.org/api takes you to the api for that specific page.
NOTE: I’m no expert on the subject, but I went through a similar process of trying to reconcile the different nuances of people’s interpretations of “REST” a few years ago, and this is the takeaway I got from looking into it at the time.
To my understanding, this stems from Roy Fielding’s Hypermedia as the Engine of Application State aka “HATEOAS”, which then becomes an enabler of the idea of a “semantic web”.
So…basically, and again as I understand it, you make your RESTful application basically self describing such that the consumer does not have to have prior knowledge of a formal contract to consume your content / functionality. They are able to engage from some defaulted root endpoint and then walk contextually relevant links that your app provides as the consumer interacts. The consumer, of course, can be a person or a systemic agent.
If you are just using “REST” for pretty urls mapped to CRUD operations that a consumer must have prior knowledge of and calls according to a well known contract, Roy Fielding would deem it not truly RESTful.
That’s not to say that a REST flavored RPC service set up can’t be useful / an improvement over a more elaborate RPC model and suitable for limited / controlled usage, but the hardliners will look down their noses at it and consider it to be degenerate / not really REST.
I had the pleasure a while ago to work with an API that had documentation that was very, very hard to understand.
Once I managed to get an actual reply from the server, it was possible to compare the documentation with the server reply and use that to decipher the documentation (and yes, deciphering it was the right term). The problem was that if a request was sent to the server that wasn’t exactly correct according to the spec, you would just get an error, and with the unreadable documentation, figuring out how to send the correct requests was close to impossible. There were also different versions of the API documentation which didn’t agree with each other and probably didn’t agree with the API itself; that didn’t help.
If there had been one command that I could send to the server, returning a list of all possible commands and how exactly to send them, that would have been extremely helpful. Discoverability is not just for clients, it’s also useful for software developers.
1