it's always a resource

2008-09-26 @ 02:10#

when you're implementing a web application that runs using HTTP, you are always working with Resources. that's what they're called - Resources. you might express that resource as an HTML Page, JSON objects, PDF document, JPEG file, etc. but you're still working with Resources.

and you can only do a handful of things to/with that Resource. using simple HTML, you can GET a representation of a resource or you can POST a representation to it. using scriptable objects like XmlHttpRequest you can also PUT a representation of a resource and DELETE a representation of it. Oh yeah, HEAD and OPTION can be used to handle selected optimizations of the GET method.

no other widely-shared methods are possible. no "add", no "list", no "update-last-name", etc.they don't exist. never did.

sure, you can 'fake' such things by combining real HTTP methods with your fake ones: GET /my-app/page.aspx?update-name=mike. but that's not only wrong, it's dangerous. or you could fake deletes using POST /my-app/page.aspx?action=delete&id=123. while it's not dangerous it's dopey. and misleading. and, ok, dangerous.

lets' agree to stop trying to put six pounds of flour in a five pound sack. when you build your HTTP web apps, define resources and use the methods given to you to work with. it might be harder to craft at first, but you'll have a better app in the end. and you might just get to liking it that way, too.