Re:How I learned to stop worrying and love REST
by grncdr on Sunday February 05, 2012 @08:11PM
(#3555817)
> I find URL templates smelly. Once you stick a place holder in the URL, it's no longer a valid URL - it's something that requires custom mangling before it can be passed along.
This is why a standard has been drafted for this particular problem, the mangling becomes standard and predictable rather than customized to each use case.
Re:How I learned to stop worrying and love REST
by buddydvd on Monday February 06, 2012 @02:17AM
(#3556542)
It may smell, but clients that uses URL templates may still be RESTful. For this to work, 1.) the server must decorate the response with the proper resource type identifier, 2.) the client must be able to understand the resource type, and 3.) the resource type spec must specify how the clients should treat URL templates.
Web browsers are REST clients that understand the HTML resource type. They, too, can generate URLs. For example, in HTML, you can specify a URL template with the following code:
<form action="foo/bar/" method="get">
<input name="baz" type="text">
<input type="submit" value="Submit" />
</form>
Input tags with type="text" are, by default, optional. Newer HTML spec allows you to annotate input tags with the "required" attribute, which allows you to specify them as required.You can define your custom resource type to do the same if you want:
{ "form": { "action": "foo/bar/",
"method": "GET",
"fields": [ { "name" : "baz" } ]
}
You can make the above example a lot leaner by trimming out features you don't care about. It's all up to how you design the spec of your resource type.
In your example, I need to know that the x is something that requires replacement. How is that fundamentally different from just putting in your documentation (and, in the 405 if not passed) "this resources takes query param baz" - which is not HATEOS?
Also, this doesn't cover the case of optional parameters. Specifying optionality in a template is horrible (something like "bar/?baz=x[&ogle=y]" to borrow the pattern from man pages), and specifying individual URLs for each combination of parameters is impractical for more than a few.