Give it a REST please

I attended DDD10 this weekend and among the presentations was one by Jacob Reimers called Taking REST beyond the pretty URL.

Jacob’s Case

Jacob’s contention here was that the examples of MVC that use actions in the URLs were an improper use of a REST approach.

His "’bad’ example was a simple bookmarks application. The URL /Bookmark lists all bookmarks and /Bookmark/{id} should represent the bookmark resource. Editing a bookmark in the original application was done via /Bookmark/Edit/{id} and there was /Bookmark/Details/{id}

His argument here is that Edit is an action and we should not be doing this via the URL, we should use a HttpPost verb on the same URL. He shows that sending a HttpGet to the MVC URL with “accepts: application/json” should return JSON and not HTML.

Why This Is Wrong

I understand his point but I think that it misses one vital thing:

Data is not an application, and an application is not data.

We are trying to treat a single URLs as both access to a resource and an application.

A good example of how easy it was to generate confusion was that Jacob’s own application treated /Bookmark as “a list of all bookmarks”.

I am not sure if this is a mandated requirement of REST but a “list of bookmarks” is not a “single bookmark”, they are two different things. I realise it’s a common convention but that does not make it correct.

So Jacob’s own application allowed us to inline-edit the bookmark in the URL /Bookmark was incorrect based on his own premise. The URL should have been /Bookmark/{id} to edit a single bookmark, which means REST is saying “the URL /Bookmark can only represent the list and not a single entry.

So this leads to the conclusion that REST requires our application cannot work in a way that differs from the REST constraints. We cannot design a pragmatic application URL structure, it must represent some fixed system. This means the REST conventions are forcing the application designer to follow a fixed convention which in many cases (including Jacob’s own example) is likely to be illogical or unworkable.

Which makes it all but irrelevant.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s