Apigee - 如何重定向到不同的资源 [英] Apigee - how to redirect to a different resource

查看:42
本文介绍了Apigee - 如何重定向到不同的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Apigee 创建的 API 代理,它可以正常工作.但是,我想更改资源名称.

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

目前,我有以下资源:

/collection/{Id}/products 重定向到 /collection/{Id}/products

我想像这样重命名代理资源:

I want to rename the proxy resource like this:

/collection/{Id}/apps 重定向到 /collection/{Id}/products

使用 Apigee 实现这一目标的最佳方法是什么?

What is the best way to to that with Apigee?

干杯,查夫达尔

推荐答案

如果您想将 /collection/{id}/apps 的请求代理到 /collection/{id}/products,使用以下代码段向目标请求添加 JavaScript 策略:

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

这篇关于Apigee - 如何重定向到不同的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆