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

Inherited a CFML Application With Few Tests? Here’s Where to Start!

Inherited a CFML Application With Few Tests? Here’s Where to Start!

You need to change an application that has been running for years.

It might be a ColdFusion customer portal, a Lucee application supporting internal operations, or a CFML system your team is preparing to modernize. People depend on it, but some of its behavior lives in old tickets, scattered documentation, and the memory of whoever has supported it longest.

Now a release is approaching. You know more testing would help. The difficult part is deciding where to begin without putting every other priority on hold.

Start with one important workflow and build evidence around what it needs to do.

Explore Ortus Quality Assurance Services

Maria Jose Herrera
Maria Jose Herrera
October 27, 2026
Your ColdFusion Upgrade Passed. Did Your Business Workflows?

Your ColdFusion Upgrade Passed. Did Your Business Workflows?

The server restarted. The administrator shows the expected version. Your homepage loads, and a few familiar screens look fine.

Would you tell the business the upgrade is complete?

Consider an illustrative scenario: a customer submits an order after an upgrade. The application saves it and displays a confirmation page. But the confirmation email never arrives, and the scheduled process that sends the order to fulfillment has not completed.

From the browser, the transaction...

Maria Jose Herrera
Maria Jose Herrera
October 22, 2026