Using CFHTTP to Build a Query

Sorry I have been lazy about posts recently. I’ve been in Boston, meeting with various product teams. All I can say is that there is some cool stuff on the horizon.

Anyway, did you know that CFHTTP can automatically turn a comma-delimited file into a query object for you? Let’s say you have a file called data.txt that looks like this:

firstName, lastName, emailAddress
Christian, Cantrell, cantrell@macromedia.com
Mike, Chambers, mesh@macromedia.com
Baby, Blue, bluebaby@macromedia.com

The following use of CFHTTP will parse the data above into a query stored in the variable “myQuery”:

<cfhttp method="GET" url="http://localhost/tests/cfhttp/data.txt" name="myQuery">

You can use the columns attribute of the CFHTTP tag to specify a different set of column headers, and you can use the firstrowasheaders attribute to include the first row as data rather than column headers. And, of course, your comma-delimited file doesn’t have to be static; the delimited values can be dynamically generated by any means.