Apigee - how to redirect to a different resource

2019-06-14 09:25发布

I have an API proxy created with Apigee which works properly. However, I want to make a change in a resource name.

Currently, I have the following resource:

<proxy>/collection/{Id}/products which redirects to <myService>/collection/{Id}/products

I want to rename the proxy resource like this:

<proxy>/collection/{Id}/apps which redirects to <myService>/collection/{Id}/products

What is the best way to to that with Apigee?

Cheers, Chavdar

标签: proxy apigee
1条回答
Summer. ? 凉城
2楼-- · 2019-06-14 10:06

If you'd like to proxy requests for /collection/{id}/apps to /collection/{id}/products, add a JavaScript policy to the target request with the following snippet of code:

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
查看更多
登录 后发表回答