Get query params/string from ColdFusion request

862 views Asked by At

I can't get query params inside ColdFusion component.

I tried to use:

  • <cfparam name="url.q2" default="">
  • cgi.QUERY_STRING
  • arguments

All empty

I have a component:

<cfcomponent extends="taffy.core.resource" taffy:uri="/public/test" hint="some hint about this resource">
    <cffunction name="get" access="public" output="false">
        <cfparam name="url.query_p1" default="">
        <cfparam name="url.p2" default="">

        <cfset result = structNew() />

        <cfset result['arguments'] = arguments />
        <cfset result['cgi'] = cgi />
        <cfset result['QUERY_STRING'] = cgi.QUERY_STRING />
        <cfset result['url'] = url />

        <cfreturn representationOf(result).withStatus(200) />
    </cffunction>
</cfcomponent>

And use this url for test: http://localhost/public/test?query_p=1&p2=test

As response I got:

{
    "data": {},
    "arguments": {
        "endpoint": "/public/test/",
        "type": "candidate"
    },
    "QUERY_STRING": "endpoint=/public/test/",
    "url": {
        "endpoint": "/public/test/",
        "query_p1": "",
        "p2": ""
    },
    "cgi": {
        "query_string": "endpoint=/public/test/",
        "request_url": "http://localhost/index.cfm?endpoint=/public/test/",

    }
}

How can I get something like? :

query_p=1
p2=test
...
1

There are 1 answers

5
James A Mohler On

You want something like this:

<cfcomponent extends="taffy.core.resource" taffy:uri="/public/test" hint="some hint about this resource">
<cffunction name="get" access="public" output="false">
    <cfargument name="query_p1" default="">
    <cfargument name="p2" default="">


    <cfreturn rep(arguments)>
</cffunction>
</cfcomponent>

You can see additional Taffy Examples at

https://github.com/jmohler1970/Taffy_Verbs_withCache/blob/master/resources/users/users_id.cfc

Disclaimer: This is my sample code