Here’s some random thoughts I’ve had about REST while interacting with commenters on my previous blog. Please, please, they are just thoughts, not rules of thumb I’m taking on. Some things to think about and ponder…
Use Links instead of PATCH
The idea of using the new PATCH HTTP operation makes me squeamish. I’m not sure why, but intuitively I don’t like it. Maybe its because so many semantics can be hidden behind it? Maybe its because a user is going to have to read a lot of documentation to understand how to interact with it? I think I’d rather use links instead. Let me elaborate. Consider this customer XML document:
<customer> <first-name>Bill</first-name> <last-naem>Burke</last-name> <address> <link rel="edit" href="/customers/333/address" type="application/xml"/> <street>...</street> ... </address> <billing-address> <link rel="edit" href="/customers/333/billing-address" type="application/xml"/> ... </billing-address> ... </customer>
If you were using links instead of PATCH, doing a GET on a specific customer resource returns you a document that pretty much describes to you how to interact with it. The “edit” link elements under address and billing-address let you know that you can partially edit the document without having to refer to any user documentation (or yuck, and WADL document) on whether PATCH is supported or how you use PATCH on the resource.