REST uses the HTTP verb (GET, POST, PUT, etc...) to tell the server what action to take. This is a problem if you need to do multiple things (e.g. an insert, and update and a delete) in a single transaction.
Therefore Espresso extends REST to allow for complex transactions. In a PUT and POST request, if objects contain certain extra attributes, they will be processed differently.
In a POST, if an object looks like the following:
then that object (the product in this case) will be looked up rather than inserted. This is useful if you need to connect some of your new objects to existing objects, but you don't want to use primary keys.
For this to happen, the following conditions must be met:
If the object in question is not found, or if more than one object is found, then the request will fail.
In a PUT request, each object may specify what should be done with it. For instance:
In this case, the first object (Customer) will be inserted, the second object (Product) will be updated, and the last object (Address) will be deleted.
There are other actions that can be specified:
This is a combination of INSERT, UPDATE and LOOKUP. The "key" is used to try to find a record as described in LOOKUP. If a single record is found, this record is updated with provided values. If a record is NOT found, the provided values are used to INSERT a new record. Checksum is NOT required and is implicitly "override".
Use of Parent Sub-Resources can be used with these actions as well.