Access API bindings

API bindings are externalized specifications created per API dependency. They can be used to store API-related configuration information, that may be stage-dependent.

API bindings are typically used to store, e.g.

  • url

  • username

  • password

  • API-Key

  • ... for the 3rd party service you want to access.

Example binding:

{
  "url": "http://example.com/dev"
}

DEV-Bindings

Dev-Bindings provide an easy way to specify some default values, which are easily accessible on all non-production stages. They are meant to be used for rapid development to avoid long and extensive configuration outside of the project.

DEV-Binding can be created and speciified inside the Solution. To do so, you go to the Integration Namespace you want ot use for interacting with this API (or create a new namespace) and create an API dependency. There you will find an input field where you can place your information as JSON formatted key/value pairs.

Attention: Please be aware, that all information entered into DEV bindings will go into the Git repository! To prevent this, you can instead create an API binding for the same purpose, since they get stored as OpenShift secrets inside the cluster.

Porgrammatically access the binding

Now that you created an API dependency for this namespace with an API dependency attached to it, you have access to this information while implementing this namespace. After you deployed your solution to a project you can log in to this project with the Solution CLI. The SDK now provides you with the information by calling

// load the bindings
const mybindings = await this.apiBindings.<name-of-the-api-dependency>();

// load binding value
const url = mybindings.url;

inside an implementation file (e.g. of a service) inside that Integration Namespace. This would assign the value http://example.com/dev to url.

Currently, only the following default parameters can be accessed with this syntax:

  • url

  • ca_cert

  • k5_propagate_security_token

If you want to use custom parameters, you can access them as follows:

const myparam = mybindings['myparam'];