-1

Suppose I want to create the following APIs:

/movies/{movieId}/cast
/movies/{movieId}/crew
/movies/{movieId}/awards

On the recent versions of Apigee, wildcards are no longer allowed in the base URL. To achieve the ones above, we first created an API proxy /movies. We then defined three separate resources under it, each starting with a wildcard:

/*/cast
/*/crew
/*/awards

Here's a couple of questions:

  1. Is this the only way to define wildcards in a hierarchical API structure?
  2. Is there a way to define these into 3 separate API proxies?
prits
  • 19
  • 4

1 Answers1

0

Say you created an API with the basepath /movies and then consume /movies/jaws/cast. You can then crate a PreFlow policy to extract the path variable like this:

<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-URI">
    <DisplayName>Extract URI</DisplayName>
    <FaultRules/>
    <Properties/>
    <URIPath>
      <Pattern>/{movieid}/{function}</Pattern>
  </URIPath>
</ExtractVariables>

You now have two variables, one for the variable and one for the actual service. Now you can create a Conditional Flow for each function (cast, crew, awards...) on the variable function rather than matching the path:

    <Flow name="Cast">
        <Description/>
        <Request/>
        <Response>
            <Step>
                <FaultRules/>
                <Name>Assign-cast</Name>
            </Step>
        </Response>
        <Condition>(function = "cast") and (request.verb = "GET")</Condition>
    </Flow>

You may still need to do some magic to rewrite your target path, but your request proxy path will still be /jaws/cast but now you can run specific policies against a request for the cast of Jaws.

See http://apigee.com/docs/api-services/api/conditions-reference and http://apigee.com/docs/gateway-services/content/flow-variables-and-conditions for more info on Conditional Flow configuration.

Michael Bissell
  • 1,210
  • 1
  • 8
  • 14
  • I wanted separate API proxies to be able to set different spike arrest limits for each. I think with this approach, that's not possible, right? Also, if there will be new sub resources, say `/*/sales`, I would have to update the proxy to include a new conditional flow. As much as possible I wanted to avoid bumping up the revision that's why I was asking if separate proxies are an option. – prits Jun 30 '14 at 03:58
  • You can add separate spike arrests to each Conditional Flow. Resources are simply conditional flows in Apigee (path + verb). In this case we make the resource (variable + verb) and get the same result. – Michael Bissell Jun 30 '14 at 17:12