I have defined a route matching api/User/:userID that I want to call the api.User handler. I’ve defined my Routes.cfm as follows:
`
// Allow unique URL or combination of URLs, we recommend both enabled setUniqueURLS(false); // Auto reload configuration, true in dev makes sense to reload the routes on every request setAutoReload(false); // Sets automatic route extension detection and places the extension in the rc.format variable setExtensionDetection(true); // The valid extensions this interceptor will detect // setValidExtensions('xml,json,jsont,rss,html,htm'); // If enabled, the interceptor will throw a 406 exception that an invalid format was detected or just ignore it // setThrowOnInvalidExtension(true);// Base URL
if( len(getSetting(‘AppMapping’) ) lte 1){
setBaseURL(“http://#cgi.HTTP_HOST#”);
}
else{
setBaseURL(“http://#cgi.HTTP_HOST#/#getSetting(‘AppMapping’)#/index.cfm”);
}
// RESRful routes
addRoute(
pattern = “api/User/:userID”,
handler = “api.User”,
action = {
GET = “view”,
POST = “save”,
PUT = “save”,
DELETE = “remove”
}
);
// default route
addRoute(pattern=":handler/:action?");
`
My handler is nothing more than:
`
component extends=“coldbox.system.EventHandler”{
this.allowedMethods = {view = “GET”, save = “POST,PUT”, remove = “DELETE”};
any function view (event, rc, prc) {
//writedump(“view”); abort;
}
any function save (event, rc, prc) {
writedump([rc,prc]); abort;
}
any function remove (event, rc, prc) {
//writedump(“remove”); abort;
}
}
`
When POSTing, my 404 handler is picking up the request. Upon dumping the prc, it appears that my specified route is not being picked up and I believe it’s using the default route.
currentRoute -> :handler/
currentRoutedURL -> api/User/
invalidevent -> api.User.index
Any thoughts on why the pattern doesn’t appear to be matching?