0

I have a simple use case of mapping path param from the API consumer to the backend API endpoint. I have done a lot of research but have not found out the specific answer on how to do that. As per my understanding, thr mapping of the path parameter can't be done without the use of uri-template. Now the problem is that the API Manager does not support uri-template from the API Publisher user interface and you have to use url-mapping instead. One blog from WSO2 developer says that you can then go to the individual synapse config and change that to uri-template manually. But what is happening in pratice is that the updates made to the synapde config somehow triggers the database update that would happen from the publisher UI otherwise and the end result is that it does not work. Can someone please provide the way forward on how the path param can be mapped? FYI - the query parameter mapping is working for me since that does not need uri-template and can be implemented using url-mapping itself.

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
dave
  • 91
  • 6

1 Answers1

0

APIM 1.8 support both uri-template and url-mapping.You can define your url-template(or if you want uri-mapping) under resource section. please see the synapse config where i have added url-template and a url-mapping

in publisher I added /json as url pattern for url-mapping and /json/{id} for uri-template

    <?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
     name="admin--mytst"
     context="/mytest"
     version="1"
     version-type="url">
   <resource methods="GET" url-mapping="/json" faultSequence="fault">
      <inSequence>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
               <send>
                  <endpoint name="admin--mytst_APIproductionEndpoint_0">
                     <http uri-template="http://localhost.com"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <sequence key="_sandbox_key_error_"/>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
   <resource methods="GET" uri-template="/json/{id}" faultSequence="fault">
      <inSequence>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
               <send>
                  <endpoint name="admin--mytst_APIproductionEndpoint_1">
                     <http uri-template="http://localhost.com"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <sequence key="_sandbox_key_error_"/>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
   <handlers>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
         <property name="id" value="A"/>
         <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
         <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
   </handlers>
</api>`enter code here`
Jenananthan
  • 1,381
  • 2
  • 10
  • 20
  • related post http://stackoverflow.com/questions/28424387/how-to-use-query-params-with-wso2-api-manager-1-8 – Jenananthan Feb 26 '15 at 09:34
  • Thanks. One follow up query that needs to be addressed, however. Could you please explain how I can read the {id} path parameter from the exposed URL and pass that as a query parameter of the target URL in ""? – dave Apr 22 '15 at 20:23
  • use {uri.var.id} and append to the traget URL[1] 1.https://docs.wso2.com/display/ESB470/HTTP+Endpoint – Jenananthan Apr 23 '15 at 04:21
  • Yes - finally I could get this to work. Thanks for your answer. The key here is that the API Manager publisher interface and manual edits to the synapse config file need to be always in sync.That was causing the issue. – dave Apr 23 '15 at 14:59