Sr. Director, Product Research, Epicor Software

Software Architecture

This blog is not associated with my employer.

Friday, August 04, 2006

Are GET and PUT Symmetrical in REST?

Does REST require symmetry? In other words, must the payload schema for messages I GET be the same as the schema for messages I PUT? I hope not, because (in my world) what I PUT is rarely a new, complete authoritative version of the data. In the work I've done, the PUT (or POST) payload explicitly indicates whether the item is new (in which case it is authoritative) or if I am changing an item that already exists.

The REST idea – in my mind – is that (a) you can address instances of data unambiguously and completely and (b) that what you GET and what you PUT (for a given URL) are semantically related -- but not necessarily exact copies.


Paul Downey said...

Here's my understanding:
RFC2616 says for PUT "the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server." If the representations differ wildly, POST maybe more appropriate - POST being in effect communicate with an agent. OTOH the resource may have many different representations under different media types - you could PUT text for today's weather and later GET back a WAV file using content-negotiation.

The benefit of PUT and GET being 'symetrical' is that an agent could cache the sent content for the next GET, eg. with WebDAV:
However RFC2616 lists PUT along with POST and DELETE as "HTTP methods [which] MUST cause a cache to invalidate an entity."

Erik J. said...

Thanks Paul. I'm currently reading the REST dissertation and the RFCs (tedious, but informative) so I can discuss this stuff, um, more informed.