Comment on page
An overview of how to configure your software application to read records from inside one of your data models
The read event allows you to retrieve data from one of your data models & send this data back to your endpoint. This can be useful if you want to get data out of your data model & display it to your users in a frontend user interface.
In this tutorial we cover:
- Setting up a GET endpoint
- Linking our GET endpoint to an action
- Getting a filtered data set
For the purpose of this example, we will use a data model that holds different types of plants, their prices, quantity & currency.
Example Plant Data Model
Our goal is to set up a GET Endpoint that allows our users to get data records out of this data model whenever the endpoint is triggered.
There are two ways to do this, we can either:
In this article we will cover how to build the endpoint, action & event from scratch.
In this section we are going to create a GET Endpoint manually to get a collection of records out of our Plant Data Model. To do this, head on over to the endpoints tab & press the "+ New Endpoint" button to create a new endpoint.
Next, we fill in the basic details for our endpoint as below.
Note, we only need to fill in the Basic options within our endpoint, since this is a GET Endpoint to get a collection of plant information & we are not sending any data to our endpoint.
Lastly, press save & close the endpoint.
Next, we need to link our GET All plant data endpoint to an action. To do this, we start by heading over to the actions tab & pressing "+ New Action".
Next we give our action a name, call it "Get all plan data".
The best idea here is to give the action the same name as your endpoint, since it will make it easier to search for in the future.
Next, under our actions Advanced settings, we link our action to our endpoint. This means that whenever our GET All plant data endpoint is triggering, this will start the action running.
Notice, because we are getting data out of our Plant Data Model, we are going to want to return this data to our endpoint. To do this, we need to declare a variable within our action. This variable will sit as a placeholder waiting to store a collection of records that our action will return when run.
To create a variable within your action, go to the variables section of the action & click the "Add" button.
The variable that we are adding here is going to store all of the data returned from our Plants Data Model. This means it needs to be able to store a collection of records Plant Data Model. To configure this we (A) set the Kind to Collection, (B) set a meaningful Label & Name, (C) set the Type to Basic & (D) pick the Model Plant Data.
Lastly, we press Save to close this popup.
The final step in the configuration is to set our actions response variable to our All of plant data variable.
To test our GET Endpoint, Action & Event, we need to (A) generate the code, (B) test our endpoint from within the endpoints tab & (C) check our endpoint response code & body for the collection of records from our Plants Data Model. The video below shows this process in action.
Notice that if you've configured this successfully, the response code will be set to 200 & the endpoint body will contain you plant data.
Ditto Tip: If your endpoint body is empty, but you get a 200 response code, then it is likely that your action is not sending a response variable back to your endpoint. You can double check this by reopening your Action & checking under the option Resp Variable.