Reacting to events

Reactions can be used to trigger external services when certain events occur.

The following examples shows the basic APIs for working with reactions.

Create event reaction definition

As an example, we are going to set up a reaction that posts notifications every time an order is placed. We need to specify the feed name and the event type to react to.

We use a POST command to configure our reaction:

curl -i https://api.serialized.io/reactions/definitions \
  --header "Content-Type: application/json" \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  --data '
  {
    "reactionName": "new-order-notifier",
    "feedName": "order",
    "reactOnEventType": "OrderPlacedEvent",
    "action": {
      "actionType": "HTTP_POST",
      "targetUri": "https://some-server.com"
    }
  }
  '
HTTP/1.1 200 Created
Content-Length: 0

Next time an OrderPlacedEvent happens you will get a POST request to your some-server.com looking something like this:

{  
   "metadata":{  
      "aggregateId":"723ecfce-14e9-4889-98d5-a3d0ad54912f",
      "timestamp":1505376578800,
      "sequenceNumber":1
   },
   "event":{  
      "eventId":"127b80b5-4a05-4774-b870-1c9a2e2a27a3",
      "eventType":"OrderPlacedEvent",
      "data":{  
         "customerId":"some-test-id-1",
         "orderAmount":12345
      }
   }
}

List reaction definitions

You can list all your reactions using a simple GET request.

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  https://api.serialized.io/reactions/definitions
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
Content-Length: 411

{
  "definitions": [
    {
      "reactionName": "new-order-notifier",
      "feedName": "order",
      "reactOnEventType": "OrderPlacedEvent",
      "action": {
        "actionType": "HTTP_POST",
        "targetUri": "https://some-server.com"
      }
    }
  ]
}

Delete reaction definition by ID

A reaction definition can be deleted but note that existing delayed reactions will be left untouched.

curl -i \
  --header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
  --header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
  -X DELETE https://api.serialized.io/reactions/definitions/new-order-notifier
HTTP/1.1 200 OK
Content-Length: 0

Continue reading about subscribing to event feeds