Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Fedora 4 supports the ability to wrap multiple REST API calls into a single transaction that can be committed or rolled back as an atomic operation.

 

After retrieving a transaction resource using the REST API, clients can send additional REST API calls within the scope of that transaction. After committing the transaction, the pending changes will be persisted in a single atomic operation. Validation, event-driven workflows, and other asynchronous operations are not triggered until the transaction is committed, which may provide a performance increase for some types of iterative tasks. Transactions can also be rolled back, as if they never occurred. 

Similar in concept, the Batch Operations API allows multiple operations to occur in a SINGLE REST API call, and will also be persisted in a single atomic operation. If the client can build the full set of changes in a single request, the batch operation API may provide additional performance benefits over those provided by transactions. If the client must build changes iteratively, this API must be used. Note: batch operations can also occur within the scope of a transaction.

 

Example

Code Block
titleCreating a new transaction resource
firstline1
linenumberstrue
curl -X POST "http://localhost:8080/rest/fcr:tx" 

...

The expires header indicates when the transaction will be automatically rolled back due to inactivity. 

Warning

Transactions are automatically closed and rolled back after 3 minutes of inactivity. Transactions can be refreshed by POSTing to /rest/{tx:id}/fcr:tx

...

API requests can be prefixed with the transaction identifier:

...

You can send most API requests scoped by the transaction. API requests that are not prefixed by a path to the node do not occur within the scope of a transaction and cannot be used (e.g. fcr:nodetypes, fcr:namespaces, etc)

 

Code Block
titleCommitting a transaction
firstline4
linenumberstrue
curl -X POST "http://localhost:8080/rest/tx:83e34464-144e-43d9-af13-b3464a1fb9b5/fcr:tx/fcr:commit

...

Fedora 4's transactions do NOT support checkpointing. After committing a transaction, it is closed, and any further operations on that transaction will be rejected. 

Code Block
titleRolling back a transaction
firstline5
linenumberstrue
curl -X POST "http://localhost:8080/rest/tx:83e34464-144e-43d9-af13-b3464a1fb9b5/fcr:tx/fcr:rollback

...