Route a path proxy query to target path

Not applicable

I'm trying to create a proxy bundle that route a proxy like '/v1/{account_id}/account/{user_id}' to a target endpoint URL as 'http://myhost.apigee.net/v1/{account_id}/account/{user_id}'. In this example, calling '/v1/abc/account/123' routed to target endpoint as:

http://myhost.apigee.net/v1/abc/account/123

I read this instruction and this but still I'm not clear about 'proxies/default.xml' and 'target/default.xml' .

I appreciate it if you can provide a simple bundle for the given example.

Solved Solved
0 9 1,520
1 ACCEPTED SOLUTION

What you describe is the default behavior for Apigee Edge. You don't need to modify anything.

Set up a proxyendpoint that has a basepath of /v1/foo . Suppose it listens on a vhost with hostname myorg-prod.apigee.net. (Or you can use your own CNAME here, it doesn't matter). This means that the proxyendpoint will handle inbound requests that begin with https://myorg-prod.apigee.net/v1/foo/

Now set up a target in the proxy bundle that points to https://foo.bar.net/v1/bah

Set the routerule to always route to this target. (This is the default behavior when you use the UI wizard to create a reverse proxy.)

If you DO NOTHING ELSE in the proxy bundle, then the inbound request like

https://myorg-prod.apigee.net/v1/foo/abc/people/1234

will result in a request being sent to the target at

https://foo.bar.net/v1/bah/abc/people/1234


By default, Apigee Edge acts as a passthrough.

The "pathsuffix" for the proxyendpoint, which is everything that falls AFTER the basepath for the proxyendpoint, will be appended to the URL you specify for your Target/HTTPTargetConnection . In the example I gave above, the /abc/people/1234 from the inbound request will be appended to the configured target URL to form the complete outbound target URL.

View solution in original post

9 REPLIES 9

Hi @Mehdi Bahrami , edit your question to provide more info. Have a look at this doc,

https://docs.apigee.com/api-platform/reference/api-proxy-configuration-reference

Are you trying to create a Proxy to call another Proxy?

I created a basic proxy bundle, have a look at it.

mehdi-rev1-2018-10-24.zip

@Siddharth Barahalikar

Thank you for the response

I understand proxy layer by applying the condition to extract variable paths but how I can forward the received traffic from proxy to the target endpoint?

for example, "abc" and "123" submitted to the target endpoints as: "http://myhost.X.Y/v1/abc/account/123" (as you stated, it would be similar to forward the received traffic to another proxy)

What you describe is the default behavior for Apigee Edge.

Not sure what you're having trouble with.

Can you Download your existing proxy bundle and attach it here?

or SHOW your ProxyEndpoint and TargetEndpoint (in their entirety! no excerpts!)

@Dino-at-Google

I'm trying to define an endpoint target which should be defined dynamically (i.e., "abc" and "123" should be added to the target endpoint dynamically.

I understand.

I will repeat what I wrote above:

What you describe is the default behavior for Apigee Edge.

Can you Download your existing proxy bundle and attach it here?

or SHOW your ProxyEndpoint and TargetEndpoint (in their entirety! no excerpts!)

@Dino-at-Google

I don't have the endpoint target. I'm trying to create one. You may update

mehdi-rev1-2018-10-24.zip (created by @Siddharth Barahalikar)

For example, I'm trying to update "target/default.xml" by routing "{user_id}" from "proxy/default.xml" to "https://googleapis.com/plus/v1/people/{userId}/people/{collection}"

How can I update "target/default.xml" to add this dynamic URL that has two patterns and the patterns' value comes from "proxy/default.xml"?

What you describe is the default behavior for Apigee Edge. You don't need to modify anything.

Set up a proxyendpoint that has a basepath of /v1/foo . Suppose it listens on a vhost with hostname myorg-prod.apigee.net. (Or you can use your own CNAME here, it doesn't matter). This means that the proxyendpoint will handle inbound requests that begin with https://myorg-prod.apigee.net/v1/foo/

Now set up a target in the proxy bundle that points to https://foo.bar.net/v1/bah

Set the routerule to always route to this target. (This is the default behavior when you use the UI wizard to create a reverse proxy.)

If you DO NOTHING ELSE in the proxy bundle, then the inbound request like

https://myorg-prod.apigee.net/v1/foo/abc/people/1234

will result in a request being sent to the target at

https://foo.bar.net/v1/bah/abc/people/1234


By default, Apigee Edge acts as a passthrough.

The "pathsuffix" for the proxyendpoint, which is everything that falls AFTER the basepath for the proxyendpoint, will be appended to the URL you specify for your Target/HTTPTargetConnection . In the example I gave above, the /abc/people/1234 from the inbound request will be appended to the configured target URL to form the complete outbound target URL.

Thanks @Dino-at-Google

It works. If I need to handle different endpoints with different polices still I have to create a proxy and different target endpoints.

In this case, if I need to handle the following target endpoints, I have to create two proxies and extract "abc" and "1234" from inbound, then call different target endpoints and replace "abc" and "1234" with the pattern of target endpoints.

https://foo.bar.net/v1/bah/abc/people/1234

https://foo.bar.net/v1/bah/abc/activity/1234

Mmmm, no.

Suppose you have a proxy configured as I described above (with a basepath of /v1/foo and the target to whatever)

  1. if you send it

    https://myorg-prod.apigee.net/v1/foo/abc/people/1234

    ...then this will result in a request like this being sent to the target

    https://foo.bar.net/v1/bah/abc/people/1234

  2. if you send it

    https://myorg-prod.apigee.net/v1/foo/abc/activity/5678

    ...then this will result in a request like this being sent to the target

    https://foo.bar.net/v1/bah/abc/activity/5678

  3. if you send it

    https://myorg-prod.apigee.net/v1/foo/ANYTHING

    ...then this will result in a request like this being sent to the target

    https://foo.bar.net/v1/bah/ANYTHING

Do you see the pattern?

If you want policies that apply WITHIN THE PROXY, then insert them with conditional flows. Within the ProxyEndpoint, you can insert flows that have conditions that match on particular URL patterns.

<Flows>
<Flow name='flow1'>
  <Condition>proxy.pathsuffix MatchesPath /*/people/*</Condition>
  <Request...>
  <Response ...>
</Flow>
<Flow name='flow2'>
  <Condition>proxy.pathsuffix MatchesPath /*/activity/*</Condition>
  <Request...>
  <Response ...>
</Flow>
</Flows>

if you FURTHER want to take action within the API proxy based on the value of the url path segments, then you can extract those segments with the ExtractVariables policy, using the URIPath element.

Regardless of these flows and policies, the passthrough behavior of the proxy bundle still applies. The entire pathsuffix is appended to the URL you configure for the target endpoint.