Dynamic API Prefixes with App Connect Global Data

Intro

You can now set up different target environments for your mobile and desktop apps.
Build against a dev API during testing and switch to production when deploying. The new prefix attribute in Server Connect and API components works with App Connect Global Data, letting you define prefixes like https://dev.example.com/ or https://example.com/ and switch between them easily without manually updating URLs.

Selecting Active Environment

You can set the active environment from the menu located in the bottom toolbar:

There are three environments available, Development, Staging and Production:

Change this whenever you want to switch to a different environment.

Defining Global Data

The next step is to define the API Actions URLs per environment. This can be done in the App Connect global options. Select App and click Define Global Data:

Right click Global:

And add a variable:

You can call the variable as you like, we call it base_url:

We will use this variable to assign the URL prefix for the API Actions for each of our environments.

In the environment dropdown we select Development and then we enter the URL prefix for the Development environment and enter the URL prefix we need:

Then we change the environment to Production and enter the URL prefix we need for it:

Click Save when you define this for all of the environments you need.

Server Connect Prefix

The next step is to set these URL prefixes in the API Actions.
Select your Server Connect component in the App Structure and add a new Dynamic Attribute:

Select Server Connect > Prefix:

And click the dynamic data picker icon:

For the prefix we select the base_url, which we defined in the App Connect Globals:

Click Select and you are done:

Now, when changing the active environment, the API Action URLs will change automatically.
When the Development environment is active the API Action will be called as:

https://dev.example.com/dmxConnect/api/myaction.php

When the Production environment is active the API Action will be called as:

https://example.com/dmxConnect/api/myaction.php
11 Likes