Discuss

Using Globals in Server Connect

On this page

Overview

We added new Global options in the Server Connect panel. The Globals allow you to define and re-use Database Connections and other Settings (1), Variables / Input Parameters (2) and API Action Steps (3) across all your API Actions in the project:

Screenshot_1|690x430

So it's no longer needed to add these Database Connection or Mailer Setup steps in every server action you need to use a database connection or send an email.

Defining Global Variables / Input Parameters

You can easily define a variable and access it from all your API Actions. One of the most common use cases are the session variables - that's what our example will show you. Select Globals and right click $_SESSION:

Screenshot_2|690x430

Create a session variable and add a name for it:

Screenshot_3|690x430

And you are done! Save the changes we made to Globals:

Screenshot_4|690x430

Now you can access the session we defined in your API Actions. Let's create one - right click API:

Screenshot_6|690x430

Add a name for your API Action and right click steps:

Screenshot_7|690x430

Add a step, which will need the session variable value. We add a Set Value step, just to show you how it works, but this can be any other step:

Screenshot_8|690x430

Click the dynamic data button to select a dynamic value:

You will see the session variable which we defined globally, select it and you are done:

Screenshot_10|690x430

Defining Global Settings

The other Global Settings include Database Connections, Security Provider, Mailer, Oauth2 Provider, S3 Storage and JWT Signing. These can be globally defined and then reused across all your API Actions.

Database Connections

Defining a global database connection is really easy. You can define as many global database connections as your project needs. They will be available for any component which requires a database connection in any of your API Actions.

First, right click the Database Connections under Globals:

Screenshot_11|690x430

And add a database connection:

Screenshot_12|690x430

Add a name for it and then click the Connection Options button:

Screenshot_13|690x430

Enter the database connection details per selected target and click Save:

Screenshot_14|690x430

If you have multiple targets using different database connections, define Connection Options per each of the targets. Just change the active target from the Target dropdown (1) and click the Connection Options button (2):

Screenshot_1|690x430

Then Save the changes:

Screenshot_15|690x430

And you can use this Database Connection in your API Actions. Right click Steps in your API Action:

Screenshot_16|690x430

And you can directly add a Database Query step:

Screenshot_17|690x430

Select your database connection from the Connection dropdown:

Screenshot_18|690x430

And you are done! You can now setup your query.

Other Global Settings

The other Global Settings can be defined the same way:

Screenshot_19|690x430

Just setup the setting you need and it's ready to be used across your API Actions:

Screenshot_3|690x430

Defining Global Steps

The Global Steps are steps which will be executed for each of the API Actions in your project. The Global Steps will be executed before your API Action step, so their data will always be available in the API Action Steps:

Screenshot_4|690x430

One useful use case is providing the logged user identity to every server action. So after you've setup your global Security Provider:

Screenshot_6|690x430

Just select Globals and right click Steps:

Screenshot_7|690x430

Open the Security Provider menu and select Security Identify:

Screenshot_8|690x430

Select your global Security Provider from the dropdown:

Screenshot_9|690x430

And enable/disable the Output option. Output is useful if you want to access the logged user Identity on your pages - to conditionally show/hide parts of the page for example:

Screenshot_10|690x430

The output, however, is not required if you want to access the user identity in your API Actions - to filter database queries for example.

Click Save and you are done:

Screenshot_11|690x430

The Identify step will run with every API Action and its value will be available for them in the dynamic data picker:

Screenshot_12|690x430

Conclusion

These are the basics of using Globals in Server Action - try them and let us know what do you think :)