Part 2: Backend terms and concepts
The Dittofi Essentials give you a "top down" introduction to essential concepts in Dittofi. In this tutorial we cover backend terms and concepts.
Last updated
The Dittofi Essentials give you a "top down" introduction to essential concepts in Dittofi. In this tutorial we cover backend terms and concepts.
Last updated
WHAT YOU'LL LEARN
Key Dittofi terms and concepts (backend only)
Data models
Endpoints
Actions
Backend Variables
Actions and Events
In the last lesson you learnt the key terms and concepts required to build beautiful and powerful frontend's on Dittofi. In this lesson you will learn the key concepts required to build robust, high performance and scalable Dittofi backends.
Data models are used to store all of your apps data. You can create them from within Dittofi's Data Models tab. In the GIF below, we create a new data model called "Products". The Products data model will be used to store our products data. Products can be anything e.g. edtech courses, trainers, mentors etc.
Each Data Model, or database can be used to store data in multiple "fields". Fields are similar to columns in a spreadsheet. Fields can be used to categorize you data by a custom typed name and type (or kind) of data e.g. text, attachment, checkbox etc.
Let's add three columns to our Products data model now: Product (of type single line text), Category (of type single line text) and image (of type URL).
You can enter data into your columns by clicking on the bottom row of your data model and filling in the form that pops up.
You can administer data by clicking on the individual cells or by expanding the entire row of data.
Add the following table of data to your Products data model.
Amazing biology lesson
Science
Theory of relativity 101
Science
The history of western philosophy 101
Philosophy
How to do kick ups lesson 24
Physical Education
Advanced calculus lesson
Mathematics
The frontend of your app connects to your backend via links, or endpoints. To create your first endpoint or to test, edit or delete existing endpoints head over to the Dittofi Back-End Actions tab. You can create and test your first endpoint in 3 quick steps.
Create your first back-end action by clicking on "+ New Action".
Configure your endpoint by clicking the "+ Add Trigger" button and selecting "Endpoint" from the dropdown.
Additionally, fill in the endpoint form as below:
Click on "Build code" to build the code for your endpoint. Next, test your endpoint code by clicking the "Run" button in the bottom right hand corner of your endpoint.
When testing your endpoint, notice two things:
Your endpoint has a URL. This is because an endpoint is just a link and links are URLs.
Your endpoint has a response code 404. The response codes let us know if the webservice endpoints have run successfully. A 404 code means that the code for this webservice endpoint does not exist. The reason for this is that the endpoint by itself does nothing. To give your endpoint some functionality, you need to associate it with an Action.
Actions give endpoints functionality. For example, you might want to create an endpoint that will fetch data out of one of your data models so that you can display it on your apps frontend. To do this you will need to create an action and link it to your endpoint.
To begin with let's create an action that is just going to return the text "Hello World" to our endpoint. We can do this in 5 quick steps.
Go to the back-end actions tab and create a new action called "my first action".
Link your action with your Get products data endpoint. To be clear this means that your action will be triggered whenever your Get products data endpoint is run.
Create a backend variable inside your action. This variable has what is called global scope within your action. This means that it can be used anywhere inside your action.
The variable, or placeholder is going to be used to store the text "Hello World" so, give it a Kind text, a name and label of "MyVariable" and set the Expression to the fixed texstring "Hello World".
Set the response variable in our action to "MyVariable" This is going to send the text string "Hello World" back to our Get products data webservice.
Build your code and test your endpoint to see that your webservice endpoint will return the text string "Hello World" from your action. Notice also that your endpoint now has a Response code 200, which means that it executed successfully.
So far we have only used text variables however, Dittofi has a complete list of backend variables for app development e.g. Collection, Number, DataTime etc.. For a complete reference guide to Backend Variables see Backend Variable Types.
Let's suppose we want to to fetch a list of products out of our Products data model. We can do this in 5 quick steps.
In the actions tab create a new action, called "Get products data". This action is going to be used to get a lists of products out of your data model.
Set your action to be triggered by your "Get all products data" endpoint. To be clear, this means that your action will be triggered whenever your "Get all products data" endpoint is run.
Create a backend variable inside our Action. This variable is going to be used to store a list list of products taken from our products data model and return this data back to our endpoint.
Note, the variable we create is of kind "collection". A collection is a list of records. In our case, this will be a list of products.
Set a "Response Variable" inside your action. This variable will return data from your Get products data action back to your Get products data endpoint.
Build your code and test your endpoint to see that your endpoint will return products data from your Products data model. Notice also that your endpoint has a Response code 200, which means that it executed successfully.
Actions get more power with the help of events. Events can be chained together inside an action to perform complex logic within your backend. For example, you might want to create a new record inside one of your a data models, send an email to a new user of your app, integrate with a third party API etc. All of this is possible with the use of event chains.
The example below shows a typical password reset event chain that chains together a custom code event, a condition event and an update event.
Each event comes with it's own form to fill in. For a complete reference guide to the Dittofi events see Endpoints, Actions & Events.
Dittofi does have a number of new terms and concepts to remember. As a reminder, here's what we just covered:
Data models: these are where you store your apps data.
Endpoints: these are links that allow apps to connect with your backend. Endpoints do nothing by themselves.
Actions: these give endpoints functionality.
Backend variables: there are many different types of backend variables and these can be used to move data around your Dittofi backend.
Events: there are lots of different types of events. These can be chained together within an action to give your actions more advanced functionality.
In Part 1 you learnt essential Dittofi frontend terms and concepts. In Part 2 (this tutorial) you learnt essential Dittofi backend terms and concepts. In Part 3: Connecting frontend and backend, we'll look at a full working example to see how the frontend and backend pieces fit together.