How to write a http client in ballerina if the URL contains version numbers

When invoking a endpoint with version numbers, we can use curl command as follows.

curl -X 'POST' 'https://example.com/dprc/echobackend/1.0.0/receiver'

However, when doing this with the ballerina client, following compiler error is seen.

http:Client httpClient = check new ("https://example.com/");

var content = check httpClient->/dprc/echobackend/1.0.0/receiver.post(request);
unsupported computed resource access path segment type: expected 'int', 'string', 'float', 'boolean','decimal' but found 'other'(BCE4031)

Upvotes: 1

Views: 88

Answers (2)

We can use quoted identifiers/identifier escapes with numeric segments - e.g., '1\.0\.0.

json content = check httpClient->/dprc/echobackend/'1\.0\.0/receiver.post(request);

Upvotes: 1

Lakshan Weerasinghe
Lakshan Weerasinghe

Reputation: 329

You can also use the "1.0.0" literal value and pass it as path parameter to the resource invocation action.

json content = check httpClient->/dprc/echobackend/["1.0.0"]/receiver.post(request);

Upvotes: 1

Related Questions