Case sensitivity in apigee resource names

Hi team,

I see there are two ways add a flow condition in apigee.

One is using 'MatchesPath' and other one is using ":="

 

For example 

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

<Condition>(proxy.pathsuffix := "/employees") and (request.verb = "GET")</Condition>

The problem with MatchesPath I see is that, the resource is case sensitive. 

ie: when calling the resource /employees it works, but /Employees don't

Instead of MatchesPath, if I use ":=", this issue is solved and resource name is no more case sensitive.

But if i lock this resource in an api aproduct (API Resources->paths)to /employees, now only /employees works and its again case sensitive. 

I would like to lock the resource and do not want case sensitivity. 

ie /employees, /Employees, /EMPLOYEES etc should work.

Is there a way to achieve this please?

Thanks

Solved Solved
1 1 343
1 ACCEPTED SOLUTION

I see there are two ways add a flow condition in apigee.

Actually there are lots of ways, see the documentation of the Conditions.

I would like to lock the resource and do not want case sensitivity.

I believe the paths in the API Product operations, do not support specifying a "case insensitive match".

As you noted you can do a case-insensitive match in the Condition of an API proxy, to direct the flow. The := operator is the alias for EqualsCaseInsensitive, according to the documentation of the Conditions. But the set of API Product operations is what defines which requests are or are not allowed, when your API proxy invokes VerifyAPIKey or VerifyAccessToken. Those are two different checks - the explicit one in the API Proxy Condition, and the implicit check on the API Product Operation done by a Verify policy, and only the former gives you the ability to do case insensitive matching.

But there is a way to get what you want. In the API Proxy, after you evaluate the Condition (case insensitive matching) , but before you call either VerifyAPIKey or VerifyAccessToken, set the flow variable named "flow.resource.name", to the "lowercase" version of the proxy.pathsuffix, or whatever path you want. So if your inbound request is like /basepath/v1/eMpLoYeEs , the proxy.pathsuffix will be /v1/eMpLoYeEs , and you want to set flow.resource.name to /v1/employees. You can do this in JavaScript like so:

 

<Javascript name='JS-Set-Flow-Resource-Name'>
  <Source>
    context.setVariable('flow.resource.name',
      context.getVariable('proxy.pathsuffix').toLowerCase());
  </Source>
</Javascript>

 

or alternatively in an AssignMessage, like so

 

<AssignMessage name='AM-Set-Flow-Resource-Name'>
  <AssignVariable>
    <Name>flow.resource.name</Name>
    <Template>{toLowerCase(proxy.pathsuffix)}</Template>
  </AssignVariable> 
</AssignMessage>

 

And then in your API Product operations, you will need to use the lowercase form of the paths.

Related discussion here.

View solution in original post

1 REPLY 1

I see there are two ways add a flow condition in apigee.

Actually there are lots of ways, see the documentation of the Conditions.

I would like to lock the resource and do not want case sensitivity.

I believe the paths in the API Product operations, do not support specifying a "case insensitive match".

As you noted you can do a case-insensitive match in the Condition of an API proxy, to direct the flow. The := operator is the alias for EqualsCaseInsensitive, according to the documentation of the Conditions. But the set of API Product operations is what defines which requests are or are not allowed, when your API proxy invokes VerifyAPIKey or VerifyAccessToken. Those are two different checks - the explicit one in the API Proxy Condition, and the implicit check on the API Product Operation done by a Verify policy, and only the former gives you the ability to do case insensitive matching.

But there is a way to get what you want. In the API Proxy, after you evaluate the Condition (case insensitive matching) , but before you call either VerifyAPIKey or VerifyAccessToken, set the flow variable named "flow.resource.name", to the "lowercase" version of the proxy.pathsuffix, or whatever path you want. So if your inbound request is like /basepath/v1/eMpLoYeEs , the proxy.pathsuffix will be /v1/eMpLoYeEs , and you want to set flow.resource.name to /v1/employees. You can do this in JavaScript like so:

 

<Javascript name='JS-Set-Flow-Resource-Name'>
  <Source>
    context.setVariable('flow.resource.name',
      context.getVariable('proxy.pathsuffix').toLowerCase());
  </Source>
</Javascript>

 

or alternatively in an AssignMessage, like so

 

<AssignMessage name='AM-Set-Flow-Resource-Name'>
  <AssignVariable>
    <Name>flow.resource.name</Name>
    <Template>{toLowerCase(proxy.pathsuffix)}</Template>
  </AssignVariable> 
</AssignMessage>

 

And then in your API Product operations, you will need to use the lowercase form of the paths.

Related discussion here.