Connect Mendix with REST-DB for Backup

Part 2

Max Bareis
4 min readDec 8, 2020

< Part 1

This is the second part of the journey on how to build a backup database in REST-DB and use it with Mendix.

Build the Backup Database in REST-DB

If you do not already have an account (it’s free) in REST-DB go here for a quick start with link to sign up.

Follow the steps in the quick start to create one collection backup. Create two fields: date (Type datetime) and changes (Type string):

Define the represenation of the backup database in Mendix with an entity with attributes date and changes (unlimited String):

As we want to retrieve the data not from the database but from the API of our REST DB via microflow the entity should not be persistent, otherwise we risk to have inconsistencies. Therefore we also do not need a newEdit Page. So create a blank page named Backup_Overview within the folder OverviewPages. Duplicate the layout of the other overview pages and fill the left part of the LayoutGrid with the Entity_Menu Snippet and the main part with a DataGrid with datasource a newly created Microflow RTV_BackupFromRest. The EntityMenu snippet was changed after the creation.

Before implementing the workflow, create Message-Definitions for Backup. Select both attributes.

Now the funny part starts, thanks Mendix for these features. Press Generate Mappings and select both import and export. The Mappings are used in the microflow.

Open the RTV_BackupFromRest Microflow and remove all Parameters if there where any. Use the action Call REST Service and set the location to the restdb rest URL.

The next thing to do is to create an apikey for the acces to the collection in restdb. Go to settings of the database (not collection settings!):

In Tab API under WebPage API press AddNew and fill the upcoming form with the collection path and the two allowed methods GET and POST

For productive data you may limit the access to your site url. But you won’t be able to test locally if you limit them now.

This api key is then added to HTTP Headers of the CallRest Action:

Go to the response tab, select apply import mapping, select our backup import mapping and store in variable. OK.

Right-click on the Action and select the Set BackupList as return value. Save.

With these few steps we have setup all we need to retrieve the data from the restDB.

Putting things in

To test the grid we need data in the DB. So we add a button NewBackup to the Grid ControlBar. The Button calls the microflow EXE_Backup:

As we are still in development phase we just need two strings as data to test the interface. We will implement the real backup part later.

After we have created the Backup with a date and a string we call the REST (Post) with Export mapping for the entire request.

So first Create the Backup (non-persistent) and fill it with a date and a string representing Date and Changes. Then use this NewBackup in the Backup export mapping. Add a new action Call Rest and select the Post method, as every backup has to be a new entry. Location and x-apikey are the same as above. But you need to specify the content, otherwise the JSON will not be accepted by the server. So add a Content-Type header with application/json as value.

Thats it. Now we can create new entries in our rest DB and list them on our BackupOverview page.

So for the last part we need to really backup our Person and Address data.

Part 3 >

--

--

Max Bareis

Full Stack Developer. Building digital things from the early 90s until now. Currently focused on low code development.