简体   繁体   中英

Apigee proxy with trailing slash “/”

I Have an API Proxy, with two flows, one which returns the details of an item following the pattern "/items/{itemId}" and another one following the pattern: /items

<Flows>
    <Flow name="Items by Id">
    <Condition>((proxy.pathsuffix MatchesPath &quot;/{Items}&quot;) ) and (request.verb = &quot;GET&quot;)</Condition>
</Flow>

<Flow name="List of Episodes">
    <Condition>(proxy.pathsuffix MatchesPath &quot;/&quot;) and (request.verb = &quot;GET&quot;)</Condition>
</Flow>

Now, I want to support trailing / to both end points and here is the issues I am facing. When i try and invoke the API with trialing / for /Items/ call, Apigee assumes it to be /Items/{itemId} with Items = "" and hence redirects and executes a different flow.

Please advice on how this can be fixed.

Simply add another line to the flow to capture both:

<Flows>
    <Flow name="Items list">
        <Condition>((proxy.pathsuffix MatchesPath '/Items') or (proxy.pathsuffix MatchesPath '/Items/') and (request.verb = 'GET')</Condition>
    </Flow>
    <Flow name="Items by Id">
        <Condition>((proxy.pathsuffix MatchesPath '/items/{itemId}')) and (request.verb = 'GET')</Condition>
    </Flow>
<Flows>

Or if you're really clever you can just add them both to the same conditional line using an 'or'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM