Prev | Current Page 290 | Next

Brad Ediger

"Advanced Rails"

com/carts/{cart_id}
A client application could use this template to generate a URI for a shopping cart.
The primary advantage of URI templates is that they are structured; the template can
be provided as an input to a web service client, rather than hardcoding the URI into
the application.
The bottom line is that opacity as a hard-and-fast rule does not always make sense.
Sometimes a graph of data accessed through links makes sense; sometimes a structured
naming system might be more fruitful.
The advantages of a structured name system are apparent with algorithmic
resources, which represent the results of a calculation. These resources are typically
infinite in number, and are accessed through names like http://example.com/search/
banana. In this case, it can make more sense to allow both the client and intermediaries
to infer semantics from the URI.
What Is REST? | 193
Representations and Content Types
Resources on the Web ???live??? and hold their state at the server, but they are only ever
accessed through the representations that they expose. Like Plato??™s cave, we never
see the resource itself; all that we see are the shadows on the wall??”the representations
of that resource.
Different representations of a resource vary based on their content types. The same
resource might be available at /users/1.html, /users/1.xml, and /users/1.js. The
formats of these names imply that they are representations of the same resource
(again, even if the names are treated as opaque and the client cannot rely on this
knowledge, it is a valuable convention).


Pages:
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302