How to handle dynamic path variable checks and conditional flows?

It may be a simple thing but not sure how to implement it.

Case is I have three resources:

  • /{customerId}
  • /{customerId}/contacts
  • /{customerId}/language
  • unknownresource -- flow without a condition for handling unknown resource requests.

Now I want to put a check if customerId is passed in for all the three resources, so I'm using ExtractVariable for extracting customerId.

If I have a request like /12345 customerId will be "12345", but If I'm doing //contacts APIGEE is removing // and populating customerId with "contacts" and executing /{customerId} flow.

I want to either raise a fault where customerId is null/empty or it should go for a unknown resource flow.

Is there any way we can achieve this for 2nd and 3rd resource?

2 6 1,446
6 REPLIES 6

Former Community Member
Not applicable

Hi @Mohammed Zuber I have attached a sample proxy (bundle) that shows how to extract customer id for the different resources & errors out if the right resource is not called. Please follow the instructions on how to import a proxy bundle.

customer-rev1-2016-09-01.zip

Hi @Prithpal Bhogill,

I did create a proxy much similar to this but instead of adding each resource specific condition, I'm keeping my unknown resource simpler without a condition.

The problem is if I make a request like:

http://zubermohammed-test.apigee.net/v1/customer///////contacts

Its still returning a response of 200 with customerId populated as "contacts", which instead should a 404 or unknown resource error. Edge is removing all the "/" and taking proxy.pathsuffix as "/contacts".

So the question is how should we handle these kind of requests? and why is edge removing all the slashes?

Yes, I tried something similar and saw the behavior you reported.

As for "why is Edge removing all the slashes?" I think Edge is collapsing consecutive slashes into one slash, rather than removing all of them. As for WHY, I do not know. It turns out there is an outstanding bug covering this: APIRT-3017

You also asked "how should we handle these kinds of requests?" What do you mean?

Do you have a requirement that a request for /v1/customer///////contacts be treated as valid and different than /v1/customer/contacts ? If so, that seems like an unfortunate URI design.

It seems like a client error to send all those consecutive slashes.

@Dino, requirement is if I'm getting /v1/customers//contacts then the flow /v1/customers/{customerId}/contacts should kick in and customerId should be blank/null.

If for some reason "customerId" from client side is not passed then request will come like /v1/customers//contacts.

So when I extract with <Pattern>/customers/{customerId}/contacts</Pattern>, Edge is filling customerId with "contacts" since it is removing any empty slashes.

For testing you can check this link :

http://zubermohammed-test.apigee.net/v1/customer/12345/contacts

In above request customerId will be 12345 where as in below case it is "contacts".

http://zubermohammed-test.apigee.net/v1/customer//contacts

I observed this behaviour of removing slashes when customerId was null from client side. Its not just with proxy.pathsuffix but anywhere in URI.

http://zubermohammed-test.apigee.net////v1/////customer//contacts


Thanks.

Is it possible for you to tighten up your pattern matches, perhaps with a regex to check for a customer id that is numeric (5 digits)? And reject the request if the customer id does not match expected format?

Is it possible for you to work around the current limitation in some other way?

Former Community Member
Not applicable

I think @Dino has already addressed your questions. Please let us know if you have additional questions.