Last year, I released a ColdFusion component - ResourceMapper.cfc - that allows you to easily translate RESTful resource requests into a server-side event and a collection of URL parameters. Today, I added a small, but powerful feature that allows you to define custom regular expression patterns for your named resource components.
By default, the ResourceMapper.cfc ColdFusion component would replace your named-parameters with the regalar expression pattern:
... such that the sample resource:
... would be compiled down to the pattern:
This works great if you're using mechanical SES (Search Engine Safe) resource definitions. But, this completely fails if your resources are formed somewhat more loosely.
To accomodate a more flexible resource scheme, you can now provide an explicit regular expression pattern for a given named parameter:
The explicit pattern much be enclosed within a set of parenthesis; and, for obvious reasons, your pattern cannot, itself, contain parenthesis. So, imagine that my resources were named such that the blogID was actually just the start of the URI component, and not the entire URI component. Example:
In this case, I could tell the ResourceMapper.cfc that my "ID" was the leading, numeric portion of the resource:
Now, the ResourceMapper.cfc will return only the numeric value as the :id and leave the rest of the URI component as generic cruft.
If you use a framework that generates URLs for you, you probably won't need a feature (or a component) like this. But, if you do things with a more high-touch approach, like I generally do, the ResourceMapper.cfc can now accomodate your URLs.