Getting Started
Start Building

Build your first rule

Let’s get started building a rule. First, go to the dashboard (opens in a new tab). If this is your first time creating a rule, it will look something like this:

1670951979.png

Start Building

Create a new rule

Click the “Create Rule” button in the top right. You’ll be presented with a dialog; fill out the request.

1670952087.png

Open the editor

Your rule will be created, and you’ll be dropped into the rule editor. Some sample data has been loaded for you.

1670952129.png

Let’s go over the sections of the editor.

The Rule Table

The rule table is the table view in the left-center area. This contains the data that defines your rule.

The rule table is split into two sections, request and response. You can always tell which section a column is in by the labels above the table. They scroll horizontally with the table.

At the top of each column is the column header. In black, the column’s name is listed. By default, this name is automatically generated from the column key. As you know, each column corresponds to a key in the rule’s request or its response. The key is included in the header cell for each column in light gray. The column header also includes an icon indicating the type.

Rulebricks supports several types of data that are commonly used in decision-making.

A list is a collection of items. Each item in the list can be of a different type. For example, a list of numbers could contain the numbers 1, 2, and 3.

Example:

[1, 2, 3]

Example operations on lists: Checking if a list contains a value, checking if a list is empty, and checking if a list has a certain length, among others.


Below the table headers are the condition rows. Those contain the conditions that define your rule (in the request section) and the values that the rule returns (in the response section). You can edit any cell by clicking the pencil icon that appears when you hover over the cell, or by double-clicking the cell.

The Sidebar

On the right side is the sidebar. It has three tabs: the request tab, response tab, and test tab. Let’s go over these one by one, while building out our first rule.

Edit the request object

The request tab allows you to edit the schema for requests. This will modify the columns, including their names and types. To provide a sample request object, open the disclosure labeled Request Format.

1670953366.png

A sample JSON object has been provided, but you can replace it with your own. For example, try pasting the following JSON object:

{
	"price": 40,
	"date_purchased": "2022-12-06T18:43:38+0000",
	"gift": false,
}

Updating columns

Then, press Update Columns. The table will update to reflect this object by creating three columns corresponding to the three keys, price, date_purchased, and gift. Notice that the types were automatically inferred from the object. Note: removing a column from the JSON schema will delete all of the data in its cells.

To edit a specific column, you can select its key in the dropdown under the Edit Columns header.

1670973054.png

Here, you can change the column’s name, type, and default value. Changing the type of a column will clear any data stored in that column.

You can also set whether the column is visible or not. Columns that have data in them cannot be hidden, and if there’s only one column in the section, you can’t hide it either.

Edit the response object

The response tab works pretty much like the request tab. The only difference is that you can’t hide response columns. If you’re following along with this guide, try pasting the following JSON and hitting Update Columns.

{
	"result": true
}

Adding a condition

The test tab allows you to locally test your rule against a particular request. That is, it will not test that the rule is actually available online- it just evaluates your conditions within your web browser.

If you pasted the two JSON values above and updated your table schema, your table should look like this:

1670973460.png

Part 1

Try adding a condition to the price column on the left, checking if the price is greater than 10.

1670973658.png

Part 2

Finally, add the value true to the result column on the right.

1670973705.png

Now the table looks like this:

1670973749.png

Testing your rule

Part 1

Great, you’re ready to test the rule. Open the test tab and paste the following JSON object. Then press the Test button.

{
	"price": 20
}

Your screen should now look like this. In the sidebar, you can see the response object that Rulebricks generated along with the HTTP status code returned with the request. In this case, the test JSON matched the first row, which is why all three cells in the request section are highlighted in green. Then, since that row succeeded, Rulebricks used the response section of that row to generate the response JSON— that’s why the cell with true in it is highlighted in blue.

1670973843.png

Part 2

Now, let’s try a different price. Replace the value 20 with 5 in the test JSON object, and press Test again.

1670974082.png

Fixing your rule

Oops! Since the price was not greater than 10, the first cell in the first row did not succeed, and the row as a whole failed. Since no rows succeeded, Rulebricks could not generate a response object. In this case, an HTTP 400 error is returned.

Part 1

To fix this issue, click the Add Row button in the navbar. This adds a blank row.

1670974242.png

Part 2

Now, replace the value in the result column of the second row with false. Press Test again.

1670974308.png

This time, the first row failed, but the second row succeeded! This is because Any will match any value. Then, Rulebricks used the response section of the second row to generate the response. Since at least one row was successful, the HTTP code is 200 OK.


That’s it! You’ve built and tested your first rule. Continue to the next section to learn how to deploy the rule to the cloud.