Hi All, I have three URI's - http://test.apigee.net/v1/students/13,
http://test.apigee.net/v1/students/13/present and http://test.apigee.net/v1/students/13/absent where '13' is the roll number of a student.
Im extracting the roll number by using extract variable policy and validating whether its present or not.
If not I will be raising a fault.
Suppose, if the URI is http://test.apigee.net/v1/students//present , its considering 'present' itself as a roll number due to which Im not able to raise the fault.
How can I solve the above problem.
Solved! Go to Solution.
I think you need to introduce flow logic that rejects such invalid URLs.
You can do this with regular expression matches.
Like this:
<Flows> <Flow name="student present-absent"> <Request> </Request> <Response> <Step> <Name>AM-ResponsePresentAbsent</Name> </Step> </Response> <Condition>(proxy.pathsuffix ~~ "/students/[0-9]{1,5}/(present|absent)") and (request.verb = "GET")</Condition> </Flow> <Flow name="student"> <Request> </Request> <Response> <Step> <Name>AM-ResponseStudent</Name> </Step> </Response> <Condition>(proxy.pathsuffix ~~ "/students/[0-9]{1,5}") and (request.verb = "GET")</Condition> </Flow> <Flow name="unknown request"> <Request> <Step> <Name>RF-UnknownRequest</Name> </Step> </Request> <Response> </Response> </Flow>
For a full working example, see attached. apiproxy-regex-url-match.zip
Here's an example of me invoking that proxy. you can see that some URLs get rejected:
$ curl https://${ORG}-${ENV}.apigee.net/regex-url-match/students { "error" : { "code" : 404.01, "message" : "that request was unknown; try a different request." } } $ curl https://${ORG}-${ENV}.apigee.net/regex-url-match/students/13 { "query" : "student" } $ curl https://${ORG}-${ENV}.apigee.net/regex-url-match/students/13/present { "query" : "student present/absent" } $ curl https://${ORG}-${ENV}.apigee.net/regex-url-match/students/13/absent { "query" : "student present/absent" } $ curl https://${ORG}-${ENV}.apigee.net/regex-url-match/students//absent { "error" : { "code" : 404.01, "message" : "that request was unknown; try a different request." } }