Extract a part of uri path.

Hi ,

I want to extract only a part of uri as follows:

Request uri : https://vidhyashinde-eval-test.apigee.net/customers.json

From the above uri , i need to extract ".json" only.

Any help will be appreciated.

Thanks.

0 4 954
4 REPLIES 4

You can use java script policy to extract it from request URI

var requestURI = context.getVariable('request.uri');
var separator = "."; 
var extension =  separator + requestURI.split(separator)[1];
context.setVariable("extension" , extension);

This will work for mentioned case , but if you have some other scenarios containing multiple separator in URI , it will be better to go with regex.

Hope this will help !!

Thanks.It worked as expected.

@Vidhya Shinde , @Amit Kumar ,

First rule of using policies, DO NOT use Apigee custom policies like Javascript , Java, Python if out of the box Apigee Policies solves same problem.

If it's a custom code we don't gurantee performance because you can end up with simple for loop with out any check that runs forever. Performance of the code depends on the quality of the code you write.

You can use extract variable policy to do same.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-Path">
    <DisplayName>EV-Path</DisplayName>
    <Properties/>
    <Variable name="request.uri">
        <Pattern ignoreCase="true">/customers.{extension}</Pattern>
    </Variable>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

-------------------------------

Anil Sagar

5997-screen-shot-2017-11-23-at-75916-pm.png Learn Apigee Concepts in 4 Minutes HandsOn

Updated the proxy and implemented as a policy...works fine.Thanks!