coldfusionroutesfw1

too much pathinfo using buildURL


I try to get an impression how to build a REST-API using FW/1 version 4. I set this in my Application.cfc:

<cfset variables.framework.routes = [
    { "$GET/persons/:id/$" = "/persons/show/id/:id" }
]>

My controller method

<cffunction name="show">
    <cfargument name="rc" type="struct" required="true">

    <cfset local.strURL = variables.fw.buildURL(
        action = 'persons.show',
        queryString = 'id=123'
    )>

    <cfset variables.fw.renderData().data( { strURL = local.strURL } ).type( "json" )>
</cffunction>

I call /persons/123 and get this output:

{"URL":"/persons/show/id/123"}

I don't like the /show/ pathinfo in this generated URL. It's not part of the URL I requested in the browser (or via AJAX etc.). Is there a way to get rid of this in the generated URL?


Solution

  • This is not a functionality in FW/1. This was considered in 2012, but was rejected.

    See: https://github.com/framework-one/fw1/issues/145

    The core issue was (and is) according to Sean Corfield:

    Interesting idea but I think you'll find that, in general, routes => URLs is actually a many-to-one mapping so you can't reliably go backwards from URLs (actions / params) to a unique route. I've talked that over a few times with people and so far no one has managed to come up with a mapping that works in all cases.