简体   繁体   中英

wso2 API Manager - How to publish an API using a template?

I have been experimenting with wso2 API Manager 1.8.0 to expose a back end(http/post) system as a REST API. I am able to get it working, but I had to edit the API configuration through the Service Bus source view as pasted below. I would like to have the same template used for all of the new APIs that get published using API Publisher to ensure that we don't have to edit the service bus source every time an API get created.

Please suggest any options that you may have used..

  <inSequence> <script language="js" key="transform_script" function="buildQueryString"/> <property name="uri.query" expression="get-property('queryString')"/> <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION"> <then> <property name="Authorization" expression="fn:concat('Basic ', base64Encode('testuser:testuser@1'))" scope="transport"/> <send> <endpoint name="testuser--AddNumbers_APIsandboxEndpoint_0"> <http method="POST" uri-template="https://testhost:8443/test/http/6731cc67-3850-4b9b-b486-62cf2a664b46?${uri.query}"/> </endpoint> </send> <bam> <serverProfile name="bam-profile"> <streamConfig name="org_wso2_apimgt_statistics_destination" version="1.0.0"/> </serverProfile> </bam> </then> <else> <property name="Authorization" expression="fn:concat('Basic ', base64Encode('testuser:testuser@1'))" scope="transport"/> <send> <endpoint name="testuser--AddNumbers_APIsandboxEndpoint_0"> <http method="POST" uri-template="https://testhost:8443/test/http/6731cc67-3850-4b9b-b486-62cf2a664b46?${uri.query}"/> </endpoint> </send> <bam> <serverProfile name="bam-profile"> <streamConfig name="org_wso2_apimgt_statistics_destination" version="1.0.0"/> </serverProfile> </bam> </else> </filter> </inSequence> <outSequence> <payloadFactory media-type="json"> <format> { "apiName": "$1", "apiVersion": "$2", "runResponse": { "runId": "$3", "runStart": "$4", "runEnd": "$5", "flowResponse": "$6", "flowResult": "$7" } } </format> <args> <arg evaluator="xml" expression="get-property('apiName')"/> <arg evaluator="xml" expression="get-property('apiVersion')"/> <arg evaluator="json" expression="$.runResponse.runReturn.item[0].value"/> <arg evaluator="json" expression="$.runResponse.runReturn.item[3].value"/> <arg evaluator="json" expression="$.runResponse.runReturn.item[4].value"/> <arg evaluator="json" expression="$.runResponse.runReturn.item[5].value"/> <arg evaluator="json" expression="$.runResponse.runReturn.item[6].value"/> </args> </payloadFactory> <property name="messageType" value="application/json" scope="axis2"/> <send/> </outSequence> 

There appears to be some documentation for the older versions of API Manager about the API template under <APIM_HOME>/repository/resources/api-templates/default_api_template.xml file.

With API Manager 1.8.0, I can not find the same documentation page but editing the velocity_template.xml works for non-prototype API definitions.

I am still trying to incorporate my requirements into it.

Actually you want to do some do some transformation for your message. APIM 1.8 supports mediation extension. where you can add your own in,out and fault sequence and have your transformation there. this mediation extension support for globally and per api basis. you can find the details here[1] so if you create a global level sequence it will be applied to all apis.In your case you have to create one global insequnce to add basic oauth related stuff and one global out sequence to add payload factory related stuff

1. https://docs.wso2.com/display/AM180/Adding+Mediation+Extensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM