mslot
mslot

Reputation: 5224

REST GET verb with parameters

I'm sitting reading on some REST with my fellow teammates, we are writing a RoR application that is going to expose some of its functionality to the rest of the world.

My task on this team is to make a ressource that exposes journal reports. If you call

http://root.com/journalreports

You should get all the journalreports from the service. Thats working like a charm, but I'm confused on how to properly make a ressource that exposes a range of journalreports. Should I make it

http://root.com/journalreports?range=1/2/2010;5/2/2010

Or is this illegal when we talk about REST because of the ?range= interference?

What is the most proper way of giving a REST ressource some parameters?

Upvotes: 11

Views: 30371

Answers (2)

manuel aldana
manuel aldana

Reputation: 16438

Parameters are perfectly OK, especially for search-resources like in your case (querying a set of journals).

I recently answered similar question (path vs. parameter)

Upvotes: 16

Bruno
Bruno

Reputation: 122649

REST doesn't make query parameter "illegal" in any way. It's an architectural style, mainly about driving the application by exchanging representations. Considering URIs are meant to be opaque, there's no real difference between http://example.com/page/1 and http://example/?page=1 for example, as far as REST is concerned (it ultimately depends on the representations that are sent, but the choice or URI style tends to be an implementation detail).

What matters is how the client are going to find out about the URIs of your reports. HTML can do this very well with forms and query parameters. Whether your service is for browser consumption or another agent doesn't really matter, you can use the same principles. You could have HTML forms (or equivalent if your client isn't a browser) if you want it to be more flexible or via explicit links on your top page. (You may find it's easier to split the range into two parameters, like "from" and "to", if you want this to be more dynamic.)

Upvotes: 6

Related Questions