0
votes

I am creating an API with some context path and v1 version:

enter image description here

Then I try to provide the sandbox and production endpoints pointing at the backends. The goal is to have the following:

PRO: http://localhost:9090/myapi/{version}

SB: http://localhost:8080/myapi/{version}

That is to say I would like to use the version field in the backend path.

enter image description here

However I am getting the following errors:

Invalid Sandbox Endpoint URI. Please refer HTTP Endpoint documentation of the WSO2 ESB for details.

Invalid Production Endpoint URI. Please refer HTTP Endpoint documentation of the WSO2 ESB for details.

Is there any way to do this?

UPDATE:

I have found the following article (https://docs.wso2.com/display/AM260/Map+the+Parameters+of+your+Backend+URLs+with+the+API+Publisher+URLs) which explains how to map values using the uri.var prefix. So now in my endpoints I have:

PRO: http://localhost:9090/myapi/{uri.var.version}

SB: http://localhost:8080/myapi/{uri.var.version}

The problem now is that its value is empty.

1
Just to clarify the requirement better, What advantage do you expect by defining the version with a variable?Rans
It is related to stackoverflow.com/questions/53720241/…. Your solution there does help remove the context path, but not the version. Using this kind of replacement {version} would allow me to use URLs like WSO2/myapp/v1/api/customers which would be translated to a backend call /api/v1/customers with the variable replacement.codependent
I'm still not very clear about the requirement. If you are trying to change where the version appears in the context path you can try to set context like "/wso2/myapp/{version}/api". I don't see an advantage of setting the backend service version using the API Manager API version.Rans
The problem is the same as in the other question, having into account that the wso2 api version is the same as the backend version in the URL I was looking for a different way to solve that problem using the variable substitutioncodependent
I just found this question that looks for the same approach: stackoverflow.com/questions/48832995/… But it doesn't have an answer to this specific problem either.codependent

1 Answers

1
votes

You may have to create an In Flow mediation policy to get the API Version to the endpoint URL.

For example, you can create a file called "VersionSequence.xml" and add the following content to that file. This sequence mediator will allow storing the REST API Version to a property called "uri.var.version".

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="VersionSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property expression="$ctx:SYNAPSE_REST_API_VERSION" name="uri.var.version"/>
    <log level="custom">
        <property expression="get-property('uri.var.version')" name="APIVersion"/>
    </log>
</sequence>

Then you can upload this mediation policy to In-Flow of the "Enable Message Mediation" section when implementing the API in API Manager. After that, you can set the endpoint as below which will get the version from "uri.var.version" property which you created in mediation flow.

http://localhost:9090/myapi/{uri.var.version}