| >It's a pattern that comes with a lot of really useful benefits. Sure, but people can implement that pattern without buying into the whole clumsy REST edifice. For example, a strict reading of REST (and RESTers support such readings!) would tell me that if I have an API that takes two cities and returns the distance between them, then I must expose a URI pointing to every combination of cities. See here: http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hyperte... >>A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) ... From that point on, all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations. ... [Failure here implies that out-of-band information is driving interaction instead of hypertext.] [emphasis mine] So, 1000 cities, you must send a million links over the network rather than 1000 possible parameters plus the formatting. Now, some RESTers assure me that, no, you can somehow communicate to the user that [prefix] / [first city] / [second city] will get you that answer; that a server can "instruct clients on how to construct appropriate URIs". Fine, but then we're right back to custom, author-documented APIs and RPCs: "to do that, format the call this way". Right back where we were before trying to force-fit everything into a CRUD mold with increasingly bizarre tables just to make all the calls work. Or maybe a REST purist would tell me that I'm supposed to link a URI for the starting city: [root]/distances/[start city]/, and then from there link them to possible choices of the second city: [root]/distances/[start city]/[end city]/ . Fine, but why jump through two pointless hoops, when I know what I want, and I prefer to just send one request rather than pointlessly spend bandwidth navigating a path I don't care for? |
> 2. instruct clients on how to construct appropriate URIs
> 3. link a URI for the starting city and then from there link them to possible choices of the second city
All three of these are possible RESTful solutions, and I can imagine situations where each of them might make sense.
But what you're probably looking for is something like this:
(Using URL templates is a potentially simpler way to achieve the same thing). This is, of course, your solution 2.There are tradeoffs involved in using this style. Are they worth it? That really depends on the larger system and all kinds of details which you've left out.