Working with API Parameters
API Parameters allow data mapping values in an API definition to be supplied as CLIENT process startup options. Possible use cases for this are:
A request URI is /api/dev/do-something in the development environment but is /api/prod/do-something in the certification / production environment. API parameters can be used to alter the URI with a value from the CLIENT process startup configuration, eliminating the need to maintain two versions of the API definition.
A service requires an API key sent in an HTTP header. The value of the API key can be supplied in the CLIENT process configuration, instead of by the application.
The following example illustrates how to alter both the request URI and an API key, without changing the API definition, when migrating an API from a development environment to a certification environment. The steps are:
Create an operation path with a path component which will contain the environment. For example: /api/{environment}/do-something
Create the operation. On the Request tab, in the Data Mapping section, add these mappings:
Target Type URI Path Component, Path Component {environment}, Data Source API Parameter, Parameter Name environment.
Target Type HTTP Request Header, Header Name the-api-key, Data Source API Parameter, Parameter Name api-key.
In the CLIENT process configuration, add options for --api-param-environment and --api-param-api-key with the appropriate values.
API Definition
Development Serverclass
== Settings for linkdepth, maxservers, maxlinks, etc are examples, not recommendations.
reset server
set server cpus 0:1
set server createdelay 0 secs
set server deletedelay 15 secs
set server highpin on
set server linkdepth 5
set server maxservers 1
set server maxlinks 20
set server numstatic 0
set server program client
set server tmf off
set server debug off
set server param api "apifile"
set server param base-url "https://dev.example.com"
set server param diag-log "+logconf"
set server param log "+logconf"
set server param monitor "api:5 diag-log:5 log:5"
set server param tcpip-process "$ztc0"
set server param api-param-environment "dev"
set server param api-param-api-key "dev-api-key"
add server example
Certification Serverclass
== Settings for linkdepth, maxservers, maxlinks, etc are examples, not recommendations.
reset server
set server cpus 0:1
set server createdelay 0 secs
set server deletedelay 15 secs
set server highpin on
set server linkdepth 5
set server maxservers 1
set server maxlinks 20
set server numstatic 0
set server program client
set server tmf off
set server debug off
set server param api "apifile"
set server param base-url "https://cert.example.com"
set server param diag-log "+logconf"
set server param log "+logconf"
set server param monitor "api:5 diag-log:5 log:5"
set server param tcpip-process "$ztc0"
set server param api-param-environment "prod"
set server param api-param-api-key "prod-api-key"
add server example