Imagine, there is a resource, for example event. User is able to get list of events in HTML format. He should be able to view that list in two ways: as a list and as a calendar. How the API should respond to this options?

The simplest approach, I think, is to pass some parameter to index action to determine which type of presentation to use, but I don't like it. Don't know why, it is not RESTful for me.

What do you think, do I misunderstood something and should keep things simple or there is a better approach?

3 Answers 3


If the content is identical, it's unclear what "differences" would be seen in list vs. calendar. If the result is a JSON or XML document, there should be no discernible difference.

if the result is an HTML page, where formatting is part of the results, then the path is the correct thing to do, since the content is different.

You have several choices.

  1. Path changes. "/path/to/resource/view/id/" works well for us. Our views include "html", "xml" and "json".

    However, your "list" vs. "calendar" may or may not be the same content, in the a single format, and a different organization. So you have a number of issues tangled up together in your question.

  2. Query String changes. This: "?view=calender" or "?view=list".

  3. Fragment changes. This: "#calendar" or "#list". These can work well in your case, since the two views seem to have different content.


The technically correct option would be to have the application look at the http accept header. This is typically so non-obvious that no one but hardcore RESTheads use it and go with url switches which are a reasonable compromise.


The way you are describing it, it would seem the list and the calendar are different resources and should have different urls.

Even if they are currently populated using the same data, I think I would lean towards viewing them as separate resources, at least partly because it any options to view them as separate representations (query string or fragments) seem a little un-RESTful.

Also, if the data behind the list and calendar diverge in the future then viewing them as separate representations of the same resource will fall apart.

  • I thought about creating two resources, but it is unclear, what is the difference between them that makes possible to consider them separately. Mar 22, 2011 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.