In the world of web it's often the case you want to deliver exactly the same data, but in a different format - XHTML, XML, JSON, image, etc.
I've just started using a method that reduces the amount of code-duplication and immediately makes it obvious which format to expect on delivery.
Basically it boils down to sending a specific parameter in the query portion of a URL. For example, let's say that the following url delivers the details of Bob Bobbins' account: