Is it possible to change the resource url of a Ballerina service dynamically.
For an example,
resource isolated function get <DYNAMIC_CONTEXT>/[string resourcePath]() {
//;
}
In above code, can we set the <DYNAMIC_CONTEXT> dynamically?
My actual objective here is to define this <DYNAMIC_CONTEXT> from the Config.toml or similar manner. So EoD, we are capable of configuring the <DYNAMIC_CONTEXT> on deployment of the service. The end user always has to follow that specific context path which is fixed from their end of view.
The easiest way is to define the
<DYNAMIC_CONTEXT>
as a path parameter and, to use a configurable variable (which we can use to provide it's value at the runtime) as shown below.If you want to change the base path dynamically, you can use
listener
lifecycle method to attach. The service can be defined as either a class declaration or a constructor expression. When attaching the service to the listener, theattach()
method can take a variable as the base path which is the second argument.