Using context variables in REST endpoint URLs in Data Services
Context variables are supported in REST service provider and consumer endpoints in Data Services. This allows you to run multiple interacting services locally in Talend Studio, while having the endpoints contextualized so that you can deploy services to various environment using a different context.
You can use context variables in the endpoint URL of tRESTRequest, tRESTClient and cREST, either an absolute or relative path.
For example, the following context variables are defined in Talend Studio.
Context | Value |
---|---|
context.full_a |
http://localhost:8090/services/customers |
context.full_b | http://localhost:8090/customers |
context.full_c | http://localhost:8090/any/customers |
context.url_a |
/customers |
context.url_b |
/services/customers |
context.port_a |
8090 |
context.port_b |
8091 |
If you specify the endpoint URL with the context variables, the service will be exposed at the following addresses.
Endpoint | Studio | Runtime | Microservice(app/docker) |
---|---|---|---|
context.full_a |
http://localhost:8090/services/customers |
http://localhost:8090/services/customers | http://localhost:8090/services/customers |
context.full_b | http://localhost:8090/customers | http://localhost:8090/customers | http://localhost:8090/customers |
context.full_c | http://localhost:8090/any/customers | http://localhost:8090/any/customers | http://localhost:8090/any/customers |
context.url_a |
http://localhost:8090/customers | http://localhost:8040/services/customers | http://localhost:8065/services/customers |
context.url_b |
http://localhost:8090/services/customers | http://localhost:8040/services/customers | http://localhost:8065/services/customers |
"http://localhost:"+ context.port_b + context.url_b | http://localhost:8091/services/customers | http://localhost:8091/services/customers | http://localhost:8091/services/customers |
context.url_a + "/rest" |
http://localhost:8090/customers/rest | http://localhost:8040/services/customers/rest | http://localhost:8065/services/customers/rest |
"http://localhost:8090" + context.url_a + "/" + System.getProperty("user.name") |
http://localhost:8090/customers/<DynamicOSLoginUserName> | http://localhost:8040/services/customers/<DynamicOSLoginUserName> | http://localhost:8065/services/customers/<DynamicOSLoginUserName> |