This one has been puzzling me and its probably fairly simple(!), so
maybe someone could shed some light on it..
I have a resource called messages. By RESTful principles, the index
method shows all messages and the show method shows a specific
message. But what is a RESTful url (and method) if I want to show a
subset of all the messages (e.g. last 30 days)?
Is it something like:
myapp.com/messages?filter=30days
or:
myapp.com/messages/30
The latter would mean that the show method was pulling a range (rather
than a reference) which I assume is not the correct behavior.
The fact that the collection of recent messages is a logical subset of resources you want to publish means they have a URL, and the collection is retrieved through GET, that's what you accomplish with
I have fresh in mind "RESTful Web Services", and know some Rails.
On the first hand I think /messages/recent/30 is RESTful, it is the URL of a logical resource. And easily doable with the builtin routes support in Rails.
On the other hand Rails uses conventions to route REST requests which are just fine. GET /invoices is expected to obtain a list of bookings. DELETE /invoices/{id} is expected to delete that booking, etc. That's what (2) expects (even in the case that (2) and (1) are not differente). I don't see any mismatch in the way things are published. Nested resources have natural routes....
The fact that the underlying controller method invoked is this or that one does not matter, you are not exposing Rails actions, you are exposing resources through URLs and HTTP verbs, who happen to be routed to actions internally. You may expose those 7 or 8 operations, or less, or more. As far as RESTfulness is concerned you still have resources, HTTP verbs, an comply with the uniform interface. No matter how many :member, :collections, etc. have published, you stay RESTful.