Run Endpoint

The Run Endpoint Event is a frontend event that allows you to trigger an Endpoint on the backend of your Dittofi App, or an Endpoint that you've written outside of Dittofi. In this article we are going to show you how you can configure a workflow to run a run endpoint event that will get data out of the backend of your Dittofi App.

For the purpose of this article we will assume that you've already created:

  • A frontend app

  • A Data Model called "Books" that will store book titles

  • A "get books" endpoint on our Dittofi backend

  • A "get books" action that is linked to a "get books" endpoint

** NOTE TWO THINGS **

  1. If you want to POST data to an Endpoint, rather than GET data, read the tutorial Run Endpoint Event (POST).

  2. If you are not sure what is a Data Model, Endpoint or Action, please read Dittofi Essentials.

Starting with our "Books" data model (as shown below) and our "get books" endpoint and action, our end goal is to set up our frontend so that every time we click on a button, we get the latest set of book titles that is shown inside our Dittofi "Books" data model as shown in the two screenshots below.

Books data model

Our goal is to be able to click on a button and get the books out of our Books data model and display it on the frontend of our app.

To achieve this we need to go through the following steps:

  • Step 1. Create a workflow

  • Step 2. Add a run endpoint event

  • Step 3. Add a frontend variable

  • Step 4. Set up a repeating group

  • Step 5. Set the workflow trigger

  • Step 6. Build your code and test it

Step 1. Create our workflow

Next, rename your workflow to "get Books" as shown below.

Step 2. Run add run endpoint event

Next, add the Run Endpoint event to your workflow and select your Get Books Endpoint, as shown below.

** IMPORTANT ** As mentioned in the introduction of this article we assume that you already have a Get Books endpoint and action set up. If you are not familiar with this terminology, please read the Dittofi Essentials guides before continuing.

Next, we need to configure our workflow to accept data the Books data that is returned from our endpoint. To do this, we use the Response As and Response Code As input boxes as shown below.

The image below shows which input holds which data. You can type any name for your variables, but it is best practice to name them something that makes sense for your use case.

NOTE If you are running an endpoint that requires you to send data to your backend to either update, delete or create records inside your backend, the options here will be slightly different.

Next, we are going to add a second event to our workflow. This event will allow us to map the data that is inside our Response As variable that can be used inside the frontend of our app.

Next, if you return to the Workflow, you can add the "Set Field" event to your workflow, as shown below.

Next, we map the data that has returned from the endpoint into our page variable.

Finally we save and close our workflow.

Step 4. Set up a repeating group

Lastly, we need to set up a repeating group. To do this, add the following sets of elements to the page: first a Container, second a Div Block and finally an image inside the Div Block. Next add a Div Block to the original Container and put Heading and Paragraph elements inside the new Div Block.

You can see what the page structure should look like by looking at the screenshot of the navigation panel below.

Next, turn the Container into a Repeating Group and assign the contents of the repeating group to the Heading, Paragraph and Image elements. Take extra care with the image element.

If you have any issues displaying your image element, you should read the article Why does my image not display?

Your final page will look something like the screenshot below.

Step 5. Set the workflow trigger

Next, we need to set up the get Books workflow that we made in Step 1. of this tutorial to trigger when the user clicks on the button. To do this, select the button element on your page and expand the workflows tab for this button as below.

Now, whenever this button is clicked, this is going to trigger the get Books Workflow which will run the following list of Frontend Events.

Where the Run endpoint event is hit, this will trigger our backend to go an retrieve data and this data will then be mapped into our Frontend Variables using the Set field event.

Step 6. Build your code and test it

Last updated