I need help with creating a route rule - resources

Not applicable

My base url is https://org.apigee.net/base which covers https://myrealurl.com/v1

I want to add different endpoints like /plants which would cover https://myrealurl.com/v1/plants.json

I cannot figure out how to do this. Do I create a route rule? If so, can you please provide me with the exact code and where to place it.

This is not working.

<RouteRule name="plants"> <Condition>(proxy.pathsuffix MatchesPath "/plants") and (request.verb = "GET")</Condition> <URL>https://myrealurl.com/v1/plants.json</URL></RouteRule>
Solved Solved
1 10 3,103
1 ACCEPTED SOLUTION

You should have an API Proxy bundle.

Within that, a single API Proxy endpoint, with basepath /base

Within that, 2 flows. One with a condition like

<Condition>(proxy.pathsuffix MatchesPath "/plants") and (request.verb = "GET")</Condition>

Another with no condition. This second is your "default" flow, and we'll use it to catch invalid requests.

Then have one target, which uses https://myrealurl.com/v1/plants.json as the target url. One last twist: use an AssignMessage to tell Apigee Edge to NOT append the inbound pathsuffix to the outbound request.

Here's a screencast showing how to construct it, interactively.

6134-screenshot-20171212-140712.png

Here's a working API proxy that does what you want, the output of the exercise I went through above:

myfirst-rev1-2017-12-12.zip

View solution in original post

10 REPLIES 10

I do not know how to post a snippet

In the editor there is a button labeled "code" . Click that and paste in your code, it will be formatted as code.

Thank you so much!

You should have an API Proxy bundle.

Within that, a single API Proxy endpoint, with basepath /base

Within that, 2 flows. One with a condition like

<Condition>(proxy.pathsuffix MatchesPath "/plants") and (request.verb = "GET")</Condition>

Another with no condition. This second is your "default" flow, and we'll use it to catch invalid requests.

Then have one target, which uses https://myrealurl.com/v1/plants.json as the target url. One last twist: use an AssignMessage to tell Apigee Edge to NOT append the inbound pathsuffix to the outbound request.

Here's a screencast showing how to construct it, interactively.

6134-screenshot-20171212-140712.png

Here's a working API proxy that does what you want, the output of the exercise I went through above:

myfirst-rev1-2017-12-12.zip

Thank you! The only thing is, for the TargetConnection URL I want it to be just like this: https://www.myurl.com/v1 and then I want a flow for plants to hit https://www.myurl.com/v1/plants.json and a flow for seeds to hit https://www.myurl.com/v1/seeds.json. The main thing I'm running into is I cannot change that targetconnection URL. It only honors one of them. What would I have to do differently in your video to make this work this way?

Yes, I expected that you would want to have a dynamic target URL. The trick for mapping an inbound path to a different outbound path, is to use a bit of JavaScript.

basically I want to take the pathsuffix on the inbound, and append .json. Like this:

inbound path outbound path
/base/plants /v1/plants.json
/base/seeds /v1/seeds.json
-anything else- N/A

The "anything else" case is handled by the "default" flow that I showed you earlier.

The other two follow a pattern, as I described above. The JS logic to apply that transformation from inbound (proxy.pathsuffix) to outbound (target.url) is...

var pathsuffix = context.getVariable('proxy.pathsuffix');
var originalTargetUrl = context.getVariable('target.url');
context.setVariable('target.url', originalTargetUrl + pathsuffix + '.json');

And that needs to run in the Target Request flow. For this change, I modified the target.url in the target default.xml to be 'https://myrealurl.com/v1/' .

Attached please find an update of the proxy that does this. No screencast for you this time.

myfirst-rev1-20171212-1438.zip

Import this and it will do what you want.

invoke it like this:

curl -i https://org-env.apigee.net/base/plants

Thank you for helping me so quickly. When I click on your zip file, I'm getting: <html><head><title>Apache Tomcat/7.0.23 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 403 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Access to the specified resource () has been forbidden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.23</h3></body></html>

whoops - my mistake. Please try again?

It still isn't downloading - not sure why. I really can't wait to see it 🙂

6137-myfirst-rev1-20171212-1438.zip

sorry, I don't know what mistake I've made. Try this one?

Yes, that below one works! I cannot comment there so I am putting this here.