1
votes

I'm having issue with what I feel is a simple url pattern match, but seeing unexpected behavior for an API I created.

I set up the API, and when I place the "URL Pattern", I do something simple like "/player/{playerId}"

When I go to the next screen to input the endpoint information, I reference my path variable as it appears in the documentation, like http://mycoolendpoint.com/playerInfo/{uri.var.playerId}

What I end up seeing is that the entire URL pattern is being appended to my endpoint. So, in the above, instead of seeing the expected http://mycoolendpoint.com/playerInfo/111, I see coming across the wire http://mycoolendpoint.com/playerInfo/111/player/111

Am I setting up something wrong when I do this syntax that it's appending the entire URL pattern to the Sandbox and Production endpoints instead of just the value of the path variable?

2

2 Answers

1
votes

API's resource is normally appended to its endpoint URL by API Manager by default So to avoid this you can follow below instructions,

  1. Create a custom sequence with the following content and save it as a .xml file.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="TestSequence">
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
</sequence>
  1. Now edit your API in publisher. In design view go to "Message Mediation Policies" section and Enable Message mediation. Now add a In Flow and upload the previously saved sequence.
0
votes

There are 2 ways you can do this by defining your API like below.

1) Define resource like this.

playerInfo/{playerId}

and define endpoint like this.

http://mycoolendpoint.com/

Or

2) Define resource like this.

/{playerId}

and define endpoint like this.

http://mycoolendpoint.com/playerInfo/

Or you can also do this as @ycr has mentioned. If you want to do that change for all APIs without creating a custom sequence file, you can add below line inside InSequence section of <APIM_HOME>/repository/resources/api_templates/velocity_template.xml file.

<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

This template is used when APIM creates synapse files of new APIs.