[LRUG] REST and Associations
Andrew Stewart
boss at airbladesoftware.com
Fri Feb 23 01:53:52 PST 2007
> 2. What is the right way to do search? Are query strings still ok in
> urls? Is search a seperate controller?
I don't know about the 'right' way, but this is how I think of it:
As well as searching for things one can execute a search. I.e.
search can be a verb or a noun.
Think of TV cop-shows where the detectives want to look for a
suspicious item in someone's house. First the detectives need to go
to a judge to get a search warrant. The warrant describes the terms
of the search they are permitted to do.
Second, the detectives go to the house, serve the warrant on the
person and ransack the place.
After the trashing the person's house they take everything back to
the lab for analysis. But they don't find anything useful. Then
another detective who has been interviewing witnesses learns a clue
which might mean that the first lot of detectives overlooked
something in their search of the guy's house.
So the detectives return to the house with the same warrant and
search it all over again.
Now, the warrant represents a search resource. Its attributes
describe a search which can be performed at any time. Each time the
detectives go the house and ransack it, they are getting results
based on the the nature of the search described in the warrant.
The next day they go to a different judge and ask for a new warrant.
This one allows them to search the garden too. So off they go.
There are now two warrants (or search resources) describing different
searches. The results which the detectives get may or may not be the
same.
Pre-REST I thought of searching in terms of a verb, i.e. calling an
action in a controller with my ad hoc query parameters.
But now I think of creating a search as a noun. This enables you to
allow the user to create their own searches/queries in the GUI and
save them. For example, in a bug tracking application, you might
allow a user to create reports like "All open bugs assigned to me"
and "All high priority bugs which have been open for more than a
month, oldest first."
Every time the user runs one of those reports, he gets the results
back. In practical terms, he calls GET on, say, query no. 2 and it
returns the results to him.
So the resource is a Search. The SearchesController has these
actions: create (store a new query), delete (forget about it), update
(modify a query), get (execute the search and return the results), etc.
> 3. Similarly what is the right way to do sorting/pagination? For
> example when I GET /posts I may want to only return the top ten in
> html - but what about in the xml respond_to do I return all of them or
> just ten? Is the idea that *exactly* the same resource(s) are
> returned, no matter the mime type or can _what_ is returned vary as
> well as _how_ it is returned?
I believe that exactly the same resources should be returned,
regardless of MIME type. In this case you have two queries: all and
recent.
Hope all that helps.
Regards,
Andy Stewart
More information about the Chat
mailing list