Saturday, July 1, 2006

How to Use Web Resources

Web resources are exposed and are accessible via networks. Anyone with sufficient credentials is free to use them and to manipulate them.

But the way these resources usually get manipulated is very problematic.

What or Who?

Basically, there are two ways to accomplish a destructive action:
  1. You can first decide that you want to destroy something (what to do), and only after making that decision will you choose who will be destroyed
  2. You can first decide who needs to be destroyed, and will only then perform the destructive action (what to do)
For example, if there is a resource on the web to be destroyed, what is most likely to happen is that someone will implement it like this:

http://resource/delete?id=x

What we see here is the decision to first switch to the what mode ("I'm now switching to the slash-and-burn mode"), and only after that the decision is made as to who to delete. The mode (i.e. delete) is declared first, and only after that do we get the identity of the resource to be deleted.

This is disturbingly wrong. It is much more advisable to switch the order of doing things, and to first decide on who is it that needs to be modified/deleted. Once the resource has been fully identified, we can perform the desired action, such as delete or update, etc.

So in the above example, we would simply say:

http://resource/x

By doing that, we will first fully identify the resource ("it's the resource x"). Only after doing that (i.e. after obtaining the handle on the resource), will we send it a message to change itself (such as delete).

This results in a much clearer, much less ambiguous implementation.

No comments:

Post a Comment