Context switching

easily switch endpoints, apikeys, usernames...

Mainly important when using apiUi as driver (outbound operations).
A context is a named set of properties that together address your system under test. A context may include endpoints, username/passwords, database connection strings and even data in message candidates.

By context-switching you can quickly change these properties saving you time and reducing the chance of mistakes.

Enable context-switching for your project by including alias names in relevant properties.

Format of an alias name:

${aliasname}

apiUi resolves alias names always at the latest possible moment so you can even assign a value from script containing an alias name. For data in requests, you can toggle resolving of aliases at operation level.

The contexts screen

Get to this screen by Project->Context properies (Shift+Cntrl+C).
This screen may also pop-up when you open a project and current named context is not amongst the contexts in the project you just opened.

A row will contain a context; a column an alias name.

Add a context

You can add a context by clicking on the first icon and give your context a name. A new row will appear with the name you specified.

Add an alias name

You can add an alias name by clicking on the second icon and enter the name. A new column will appear with the name you specified.

An example

Below you see two contexts with three aliases and you can see that the currently chosen context is T2.

Suppose that you have a database connection string filled with dbs://crm/${database}/data and context T2. With this configuration the database connection string will resolve to dbs://crm/dbst2/data.

How to switch context

When you start apiUi, the GUI-application, it starts-up with the context that was set when apiUi was last closed. That may be or not be the context that you want to work with. Also on opening another project, you may need to switch context.
There are several ways to set the context.

  1. Use the contexts screen (apiUi only)
  2. from the command line
  3. by a script function
  4. by sending a request to the api of apiUi/apiUiServer as decsribed below

By calling an API

Applicable when using tools like Robot FrameWork as a testdriver.
You can set the context for a running instance of apiUi or apiUiServer with a POST to the api /apiUi/api/context with application/json as Content-Type header and body {"name": "T2"}.

curl example from a Windows DOS-box:

curl http://localhost:7777/apiUi/api/context -H  "Content-Type: application/json" -X POST -d "{\"name\":\"T2\"}"