5
I’m studying about web API’s and REST and the book I’m reading says the following:
The Web is built around three main concepts: resources, URI’s, and representations.
A resource is anything that has a URI. A resource itself is a conceptual mapping to one or more entities
This left me quite in doubt. I always thought a resource was the entity itself. For example, we have a file index.html
that has a URI servidor.com/index.html
, I thought the resource itself would be this file.
Another example of the same type would be to have an object Cliente
which can be retrieved from a database via a URI containing your ID servidor.com/api/clientes/123
, again I thought the feature would be the returned object.
On the other hand, I know that a certain URI can simply receive data and perform some kind of action on the server, without returning or modifying a persistent entity on the server. The book even gives an example of this
A feature can be a service that provides an interface to anything like a catalog, a device (e.g., a printer), a wireless opener for a garage door...
In the case of both the printer and the garage door, there is in fact no entity on the server. The URI will simply allow the execution of some code.
What it means to be a conceptual mapping to one or more entities?
Editing: Thinking a little about this I arrived at the following way of thinking: a resource is anything that can be accessed from a URL. For example, the homepage of a website, or a client with a certain ID. The feature is not the file index.html
in itself, neither the JSON object containing the client data, because these two things are only the state of it at that time (are representations), so the feature is in reality the concept that lies behind these states: both the page, and the client.
Is that what a resource is? If so, why can it be considered a conceptual mapping to one or more entities?
It has a URL and it has a URI. The concepts are a little different. Here’s an English page that puts a little light on it. http://searchsoa.techtarget.com/definition/URI
– Peter
Thanks @Peter, I know, URI’s can be both URL’s and URN’s. With regards to URI’s and representations I think I get the idea. What I’m not understanding very well is why a resource is a mapping to one or more entities.
– SomeDeveloper
"In the case of both the printer and the garage door, there is in fact no interface on the server.". I think so. Try to format the hard drive fully, then turn on the printer. Nothing will come out on paper. It has a "software" interface (driver) and also has a physical interface to communicate. Same thing with the keyboard (formerly type ACIA 6850 for example). So we can probably say that ACIA 6850 is a physical "resource" type "input". Not very easy, but interesting! :)
– Peter