To kick things off, let's set up a project in FL0 and create some badges. A badge is simply an image file that will be attached to a user's profile. Users will receive a badge when they accomplish a goal, such as reaching a new level.
In FL0, a project is a container that holds all of the artifacts for a backend service, including flows, variables, and configuration. Projects are versioned independently of one another and can exist across multiple environments.
To create a project:
- Log in to FL0.
- Click Create a new project.
- In the Project Name field, enter R3wards.
- Select a hosting region.
- Click Save.
Then select the project to open it.
By default, all projects have a built-in database. You can use this database to store and manage structured data across one or more tables.
In this case, we want to create a database table to store the project's badges. For each badge, we need to store the following attributes:
- A unique identifier
- A human readable name
- The file path of an image file
To create a database table for the badges:
In the Explorer pane, click Create new.
Select New Table.
Tap the Return key.
Switch to the Configuration tab.
Create the following columns:
Name Data Type name String img File
By default, all database tables have an Id column with a Data Type of Guid, so there's no need to create one yourself.
At the moment, the badges table is empty. To get some badges into the table, you need to create a flow that inserts a record.
A flow is a sequence of events that runs at a certain point in time, such as on a recurring schedule. You can use flows to create complex business logic by dragging, dropping, and connecting components within the flow editor.
There are three different types of flows, including:
Each type of flow is triggered by a different type of event.
In this case, we want to create an API flow. This type of flow is triggered by sending an HTTP request to an endpoint hosted on FL0's servers.
To create an API flow:
- In the Explorer pane, click Create new.
- Select API.
- Type Insert badge.
- Tap the Return key.
After creating the flow, it automatically opens in the editor.
All flows are made up of components.
Components are building blocks that perform some kind of action within a flow, such as retrieving data from a database or sending an HTTP request to a third-party API. It's these components — and the connections between them — that define the business logic of the flow.
By default, all flows have a Start component. This component defines the details of how the flow is triggered. For example, these are some of the configurable details of an API flow:
- HTTP method
- HTTP headers
- Query string parameters
(The available options depend on the type of flow.)
To configure the Start component for the Insert badge flow:
- Open the Start component.
- From the Method dropdown, select POST.
- In the URL field, enter /insert-badge.
- Create a query string parameter called name.
- From the Input Type dropdown, select File.
- In the Accepted Content Types field, enter image/png.
Most components output data. Later steps in the flow can then access this data via dropdown menus:
After selecting some data from this menu, a syntax that resembles the following appears in the field:
This syntax is an example of an expression. It's evaluated at runtime and replaced the result of that evaluation. Expressions can reference both steps and variables, and can be manipulated with a variety of functions and operators.
Throughout this tutorial, all expressions are provided in full. You can simply copy these expressions into the relevant fields.
In this step, we can use expressions and the Save File component to save the badge's image file:
- Add a Save File component to the flow.
- Rename the component to saveBadgeImage.
- In the File Name field, enter
- In the Content Type field, enter
- In the Content (Base64 Encoded) field, enter
You can use dot notation to access nested data (e.g. the properties of the
After downloading the badge's image file, the flow needs to insert the badge into the badges table. You can accomplish this with the Insert component.
To insert a badge into the badges table:
Add an Insert component to the flow.
From the Table dropdown, select badges.
Configure the component with the following columns:
Column Value name
The last component in every API flow should be an End component. It's this component that defines the HTTP response of the flow's endpoint.
To create an HTTP response with the End component:
- Add an End component to the flow.
- From the Status Code dropdown, select 200 OK.
- From the Content Type dropdown, select application/json.
- In the Body field, enter
Based on this configuration, the response body contains the data of the newly created database record. The data of the record is available via the output of the Insert component.
This is what the complete flow looks like:
By default, FL0 automatically generates a Swagger (OpenAPI) specification for a project's API flows. You can access this specification via the Swagger icon in the sidebar.
The specification contains a list of URLs for triggering flows via HTTP requests.
To send a request to the Insert badge flow, run the following command via the command line:
curl \ --location \ --request POST '<insert-badge-flow-url>?name=alpha' \ --header 'Content-Type: image/png' \ --data-binary '@<file-path>'
<insert-badge-flow-url> with the URL of the endpoint and
<file-path> with the path of a PNG mage file.
Updated about 2 months ago