Today I found out about a non-publicised hidden function in the Lucee CFML engine:
Let’s take a look at what it is and how you might use it.
What it is
This function essentially acts as an internal http request, allowing you to make a request to the CFML engine internally.
It’s not actually an http request as we currently know it, but it acts the same way and produces similar results.
Here’s a quick example.
Let’s say my application has an all-powerful template that returns some crucial JSON (impressive, right?):
If we hit that page directly in the browser we would receive the expected JSON response:
We can make the same request to the template from elsewhere within our application using the
This request would result in the following struct response:
Let’s update the example and send some information through in the
By sending through the
url property in the function, we are effectively calling the given
template as if we were requesting it directly in the browser like so:
The updated response would look like this:
How you might use it
It’s a great function that can be used for making internal http requests, so you might have a use case for it somewhere within your application (perhaps in a controller where you’re calling an API module prior to rendering the template).
For me, this function opens a lot of doors when it comes to creating integration tests.
Let’s assume that I have an API template within my application and I want to run integration tests on it using TestBox to make sure that the actual code performs as expected, and not testing against a mocked version.
_InternalRequest, we can easily make these requests to internal templates and actually test the responses that your app would give to users.
Here’s a breakdown of the arguments accepted by the function:
template - template path (script name) for the request (example:
method - method of the request (
urls/url (alias) -
URL scope passed to the request (query string)
forms/form (alias) -
FORM scope passed to the request
cookies/cookie (alias) -
COOKIE scope passed to the request
headers/header (alias) - Request header entries passed to the request
body - body to send with the request
charset - charset used for the request, if not set the web charset is used
addtoken - if yes/true, add
urltoken as cookie
A detailed breakdown of the complete function data can be found in the following gist on trycf.com.