我有一个用Apigee创建的API代理,它可以正常工作。但是,我想在资源名称中进行更改。
目前,我有以下资源:
<proxy>/collection/{Id}/product
重定向到<myService>/collection/{Id}/products
我想重命名代理资源,如下所示:
<proxy>/collection/{Id}/apps
重定向到<myService>/collection/{Id}/products
Apigee最好的方法是什么?
干杯, Chavdar
答案 0 :(得分:0)
如果您要将/collection/{id}/apps
的请求代理到/collection/{id}/products
,请使用以下代码段向目标请求添加JavaScript政策:
var collection_id = 10; //you should get this using context.getVariable()
var path = '/collection/' + collection_id + '/products'; //new path
var current_target_url = context.getVariable('target.url'); //get the existing target url
context.setVariable('target.copy.pathsuffix', false); //tell apigee to not copy the path over to the target
context.setVariable('debug.js.path', current_target_url + path); //this line is only for seeing the value in the trace tool
context.setVariable('target.url', current_target_url + path); //set the new path