Sometimes when you define an incoming API route, you want it to match certain environment or aspect conditions. The addRoute()
has an argument called condition
, which can be a closure or UDF pointer that must return a boolean
and receives the incoming requestString
. You can then decide if the route should execute or just be ignored.
So if a route matches via the pattern
, then this closure/UDF is called to verify the route with your own custom conditions. This is a great way to create some routes that must match certain environment criterias before they fire. Let's say you only want to fire some routes if they are using FireFox, or a user is logged in, or whatever.
// condition closure function(requestString){} // Routing with condition addRoute( pattern="/go/ff", response="Happy Resting!!Hello FireFox!
", condition=function(requestString){ return ( findnocase( "Firefox", cgi.HTTP_USER_AGENT ) ? true : false ); } );
Add Your Comment