Add a New Hook

{
  "username": "root",
  "password": "root",
  "q": "hook-add",
  "ds": "ds",
  "c": "c",
  "p": {
    "type": "event/transaction",
    "operation": "insert/update/delete",
    "url": "https://<url>"
  }
}

Adds a new hook on the specified collection. The hook can be registered on the entire datastore by not specifying any collection by skipping the c parameter.

The details of the hook to be added are specified inside the payload p.

The operation parameter in payload p corresponds to the operation for which the hook will be registered. The value of operation parameter must be one of insert, update or delete. The insert value corresponds to a record insert operation, update corresponds to a record update operation and delete corresponds to a record delete operation.

The type parameter in the payload p specifies if the hook is an event hook or a transaction hook. The value of type parameter must be one of event or transaction. An event hook is a simple observer hook. An event hook is called in an asynchronous manner after the transaction is successfully committed. On the other hand, transaction hooks are called in a synchronous manner before the final commit phase of the on-going transaction. A transaction hook must respond back with a commit or rollback outcome, which will result in the on-going transaction to being correspondingly committed or rolled-back.

The url parameter in payload p corresponds to the URL on which the hook is hosted. The database will invoke a POST request on the URL passing JSON data corresponding to the hook.

See the section on Hooks for understanding more about how Hooks work.