Blog

Luis Majano

March 23, 2016

Spread the word


Share your thoughts

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="

Hello FireFox!

", condition=function(requestString){ return ( findnocase( "Firefox", cgi.HTTP_USER_AGENT ) ? true : false ); } );
Happy Resting!!

Add Your Comment

Recent Entries

Into the Box - Updates as of June 27th, 2022

Into the Box - Updates as of June 27th, 2022

Into the Box Super Early Bird ticket pricing is over, but you can still get the Early Bird. Last week we had more episodes of the Modernize or Die Podcast - Conference Edition for ITB 2022 and announced the first 2 groups of Pre-Conference Track for Into the Box.

Gavin Pickin
Gavin Pickin
June 27, 2022
ColdBox 6.7.0 Released

ColdBox 6.7.0 Released

 

I am incredibly excited to announce the release of ColdBox v6.7.0 and its standalone companion libraries: CacheBox, LogBox and WireBox. This is an action packed release for all internal libraries with a big focus on performance, async programming, task scheduling and testing. With that said, let's explore this release. How do you update?

Luis Majano
Luis Majano
June 24, 2022
Ortus Content Digest for week of June 24th

Ortus Content Digest for week of June 24th

What has Ortus been publishing this week? We have the CFML News Podcast, more ITB Workshop Podcasts, some CFCasts and YouTube Videos, lots of Ortus and ITB Blog Posts. We have a lot more planned for next week as well

Gavin Pickin
Gavin Pickin
June 24, 2022