I wonder how to establish transaction safety in RESTful APIs, where everything is built around single entities.

Example
=======

Database model:

* Invoice
* Item

User-performed steps in the browser:

1. Change order number.
2. Add an item.
3. Remove an item.
4. Edit an item.

Requests made:

1. `PATCH`/`PUT` invoice data/order number.
2. `POST` item.
3. `DELETE` item.
4. `PATCH`/`PUT` item.

Issue
=====

If after any of the requests above an error happens, further calls might mess up the data integrity. Additionally previous requests have to be made undone. E.g. if deleting the item fails, then steps 1 and 2 have to be rewound in order for the overall invoice to be how it was before.

Another problem that might arise is a browser crash, dying internet connection, server failure or whatever.

How can one make sure that certain actions are executed in some kind of transaction to maintain data integrity and safety?