Understanding Events
We write rules in ReQL
DSL to process an "event"; an event in regle
is a JSON data that regle
receives via an API endpoints (covered in later section).
Events sent to regle
must be an UTF-8 JSON object with 2 fields, "name" and "data", where "name" is a string describing what "data" field holds.
"Data" field is an arbitrary JSON object that can contain any data.
Event Schema
{
"name": "string",
"data": { ... }
}
Playground Event
For this tutorial, we will use events from https://pg.regle.dev.
regle.dev provides a generated event stream for testing and verifying ReQL rules. This is a fake data stream meant to simulate an online marketplace.
The output is a list of new-line (aka \n
) delimited JSON.
Let's sample an event via curl and get a feel for what an event looks like:
$ curl 'https://pg.regle.dev/event/?name=login&count=1'
filter
specifies we only want to receive events with "name"
field equal to "login"
count
limits the result to 1 event
You should see an output similar to below (after prettifying the JSON output)
{
"name": "login",
"data": {
"user": {
"email": "[email protected]"
},
"ip": "127.0.0.1",
"loginSuccess": false
}
}
The event JSON is fairly self-explanatory. It includes the IP user tried to login from, user's email , and whether the login attempt was successful or not.
This is the event we will use for the rest of the tutorial.