Is there a difference/preference between `cfhttp()...
# lucee
d
Is there a difference/preference between
cfhttp()
,
http()
, and
new http()
? Only in cfscript, nothing in tags. Do they all just do the same thing in the end? I’m open to technical reasons as well as purely opinionated reason for one over another. 😄 Same goes for
cfmail()
,
mail()
, and
new mail()
. (Probably query too?). https://trycf.com/gist/a64de461322a60abf09b1f3fd7b9e1a1/lucee5?theme=monokai
s
I think
new http()
was at one point inferior but I can't remember why. It's been years. 🙂 We prefer the hyper library on forgebox for http calls anyway.
d
I found stuff about it being inferior on old versions of ACF, but can’t find anything about Lucee.
m
portability imo is the main reason to choose the first. the second doesn't work in acf, and the 3rd doesn't work in acf 2025+
s
It may be the same on Lucee, but the syntax is quite old so there's certainly no advantage to it
b
Hey Dan, I can't confirm what sknowlton mentioned about new http(). He might be right, but there are good use cases for using it. Maybe it's because it is a little more verbose. I've had the opportunity to bounce between ACF 2023 and Lucee, so I know there is a syntax difference using cfhttp. But they all function the same. The http() method (inside cfscript) is what I use the most. Hope that helps.
r
It is mentioned that using new htt() and the like is deprecated in acf 2025.
d
Right, but wondering specifically about Lucee.
b
I just tested new http() on Lucee 6.2, works great.
Reuben's comment made me want to check that to be sure.
d
If you check the trycf link I posted above, it shows all three options returning the exact same thing.
b
Yes thanks, and it looks like they all executed in 0 ms too. LOL, Reuben's comment prompted me to check my own code... just to be sure. As an example, I use new http() when making calls to the Stripe API. It's a nice way to create a single authentication function using new http(), that can be reused in various API calls. Not sure you can do that with just an http() method.
r
I would check the documentation for the functions to see how you would replicate the functionality of new http() vs cfhttp()/http() . I get worried when using deprecated functions.
d
Nothing is deprecated on the Lucee docs. They all appear to be valid.
🎯 1
r
right - I mean that ACF is deprecating them.... I try to write my code so it runs on lucee or ACF since I have seen clients switch engines before and don't like to refactor things if I can help it
b
Hey Reuben, yeah that is a valid concern... trying to keep your code universal to both engines. But with cfscript, both ACF and Lucee handle it differently, there is no way around it. When it comes to ACF, BoxLang, or Lucee, I still prefer how Lucee handles cfscript functions the most. To me, they just feel better, hard to explain. dump() instead of writedump(), echo() instead of writeoutput()... that kind of thing. At least what we learned today is that cfhttp(), http(), and new http() all do the same exact thing. Just pick the one that makes sense to you.
z
Don't use them! They are just cfml wrappers around the original tags
s
Have to say, it would've been bizarre to see
new http()
recommended in 2018
This stuff is old old old
💯 1
d
But why? Is there a reason or is it really just preference?
@zackster so you're saying to just use http()?
z
Yup
If you need to wrap it, use your own code
s
It's different from the syntax in pretty much the whole rest of the language? It makes it look like a Java object but it isn't? It was there for backwards compatibility many years ago and that's not a concern anymore?
Even
http()
isn't particularly modern as you can't chain it without a wrapper library like hyper, but it's fast and gets the job done
d
They all end up calling the same thing in the end though, it sounds like?
z
Yup
d
Interesting
z
It's open source ;)
s
But we don't write unnecessary wrappers that don't add any value for most things, so why would we use one there
not that there aren't reasons you might want to wrap it, there are (hyper being one), but some alternate syntax that looks different from the rest of your code but isn't actually? we would interview people who wrote that way sometimes 5-6 years ago and it was dated then
z
There are some neat tricks in those wrappers tho, like being able to hide the first three calls from a stacktrace
s
like there should be a reason behind the way we write, not a reason to just keep on keepin' on
d
Agreed. I'm not advocating for one way or another. Totally just trying to learn if there are actual differences. This has been super helpful.
Side note: I've looked at hyper several times over the years and just haven't felt the pull to jump into it. Maybe our API calls are all just fairly simple?
s
No reason to use it if it's not adding anything you need. I find it useful for debugging mostly
or whenever the other side of the API is doing something funky and I want to introspect it, or debug my request at length
Kind of like qb and QueryExecute. A builder just gives you a lot of options and a way to programmatically construct things without:
Copy code
var myHttpCall = { 'foo' : 'bar' };

if ( someThing ) {
   myHttpCall.baz = "frobozz";
}
b
Cool. I was not aware that cfhttp() was more or less an abstraction of http(). For that I think zacksters advice is pretty sound. And following that advice, it also makes sense to "use your own code" as he says, at least when you can. Keep it pure, keep it simple. I think zacksers way of thinking might be a contributing factor why Lucee 6.2 is 50% faster.
❤️ 1
q
I personally use
new http()
for most of my projects. It's closest to Java, and that's the other language I use all the time. I do know that the protocol cfcs were discontinued in ACF.... but at this point I don't do new projects with ACF and I'm no longer making stuff backward compatible with it either. The
cfhttp()
implementation is like nails on a chalkboard for me.
g
But what is wrong is using tag based cfhttp It works in all cases and across engines
r
technically nothing - just a question on if you are working in cfscript or not
🎯 1
z
cfscript http url="https://www.lucee.org" method="get" result="local.result" { httpparam type="url" name="id" value=1; }
Copy code
<cfhttp url="<https://www.lucee.org>" method="get" result="local.result">
            <cfhttpparam type="url" name="id" value=1>
        </chttp>
cfscript
I only use tag islands mostly for quick refactoring or <cfquery>
b
@zackster: "tag islands" ❤️
q
cfquery is really the only place I use tag islands...