Creating Additional Routes

There are several methods of creating routes. This method allows you to explicitly define patterns, verbs and handlers.

Adapt the /config/Router.cfc file with these lines (replace the existing lines about /users with these)

route("/users/:userId").withAction({GET:"show",PUT:"update",DELETE:"delete"}).toHandler("Users");
route("/users").withAction({GET:"index",POST:"create"}).toHandler("Users");

Notice how /users/:userId is above our existing one. This is because the ColdBox router system works from top to bottom to match the route patterns. It uses regex and will use the first route that it finds that matches the pattern. Is this was reversed, the :userid pattern would never run because the more generic pattern would match first.

tldr: Put your more specific patterns above the more generic ones.

Last updated