REST : pretty URLs vs ugly HTML ?

RESTfulness is in the air and you gotta try it to keep on top of your game. Which I did recently with help of my friends Rails and script/generate scaffold_resource.

Want to show a post ? GET http://…/posts/1. Remove another one : DELETE http://…/posts/2 or add a new one : POST http://…/posts. Add .xml and you’re talking in the web service language.

This is clean, simple and gives back url its original meaning : a resource locator and not a command to be proceed.

But there’s one hic. HTML only supports POST and GET (and only GET for links). This is like trying to talk french to a japanese trough a russian translator.


<a href="/posts/1" onclick="if (confirm('Delete ?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete</a>

– Sample of a link to delete a post

Ugly, not ?

But users wont see the HTML, only the url. And a clear url can sometimes replace a basic breadcrumb.

Leave a comment

Filed under rails

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s