Hidden Gems in CF2018, part 4 – Dev features: CFML REPL, CFFiddle, and REST Playground
In part 4, we begin to turn our attention to developer feature changes in CF2018, particularly the new CF2018 CFML REPL feature, the CFFiddle site, and the CF2018 REST Playground feature.
In part 4 of this series on CF2018 Hidden gems, we turn our attention to more developer-oriented features. First up, this article will discuss the following new developer-oriented features that you might miss:
- CF2018’s new command-line CFML REPL
- CFFiddle site, for testing/sharing CFML code
- CF2018 REST Playground feature, for testing REST calls
And here are the previous 3 parts so far:
- Hidden Gems in ColdFusion 2018, part 1: Series Overview
- Hidden Gems in CF2018, part 2: Installation, Administration, and Configuration
- Hidden Gems in CF2018, part 3 – Security, Performance, and the PMT
And don’t worry, if as a developer you were more interested to know instead about language additions and changes, I’ll cover that in the next part. But don’t drop off here: perhaps some aspects of these new features may benefit you in your development.
CF2018’s new command-line CFML REPL
If you’re familiar with the concept of a REPL (read-eval-print-loop) command-line tool, as is offered with many modern platforms, you may have wished for that in CF (or you may have looked to and found great value in the open source Commandbox implementation of a CF CLI,,REPL and more.
You may also know that CF2016 did introduce a new command-line interface (CLI) for CF. It was rather simplistic: it allowed you to point to a cfm file to be executed at the command line, via the cf.bat or cf.sh file found in CF’s cfusion/bin folder. It did not require that CF be running. It could run such a CFM file independently from a running CF engine, could leverage an application.cfc, and more. This could be useful, perhaps, for automating execution of CFM files as other than web requests, such as for operating system scheduled tasks or CRON jobs, or perhaps in some scripted configuration process.
But that wasn’t a true REPL, where you would actually write and execute CFML from the command line, interactively. CF2018 adds that with the new CF REPL. And you still use the same cf.bat or cf.sh to run it, but if you don’t pass a cfm file name as an argument, it presumes to open in interactive mode, ready for you to enter cfscript and more. Here’s a screenshot if starting it up and using its “help” command:
The value of a REPL is not just that you can write code at the command line, but that as you write it, you see displayed the result of expressions, functions, assignments, and more. You can also output to the command line with writeOutput and writeDump, of course. Again, CF need not be running. You can also type help (as shown above), to get more.
But for still more details, including examples, let me point you to Adobe resources which also explain how you can run (and terminate) multi-line statements, how to prevent that automatic display of output (if you prefer), and more:
Sometimes, you may want to work with CFML and you don’t have CF even installed, or you don’t want to figure out how to get to the command line. There’s a useful solution from Adobe for that…
CFFiddle site, for testing/sharing CFML code
Folks in other platforms have had “fiddle” sites where you could easily “try out” code easily, such jsfiddle.net and phpfiddle.org, where folks could enter and execute those languages without installing anything at all.
For those who didn’t know, Adobe has had a similar web-based CF Fiddle site, CFFiddle.org site for over a year. So it’s not technically new for CF2018, but it does support running code in CF2018 (or CF2016), and it was updated in the CF2018 timeframe to no longer REQUIRE that one login to use the tool. (Curiously, if you DO choose to login, it still offers only Facebook and Google authentication, not Adobe account authentication.)
Like the other fiddle sites, it’s an interactive web-site for running CFML, including code coloring. You can save scripts to share with others, and more.
Speaking of sharing scripts, the CF docs team is working to make many of the CF docs have links to such “live” demos, using CFFiddle. People are also using it to share links to demo problems in the CF bug tracker, and more. For more on the docs team efforts, see these blog posts:
- CFFiddle for Array, String, and Math functions
- CFFiddle for Spreadsheet, List, Struct, and Date/Time functions
- CFFiddle for Flow control tags and a few more functions
And to find out more about the CFFiddle project, or to share feedback, see these Adobe blog posts:
- ColdFusion Fiddle project – CFFiddle
- CFFiddle- Code, test, and share your ColdFusion code on the go!
Before leaving this subject, I would be remiss not to mention that there was a similar kind of site, to test any CFML, which long-preceded CFFiddle, at trycf.com, created and maintained by Abram Adams. It not only lets you run CF 2018 and 2016, but also CF 11 and 10, as well as Lucee 5 and 4.5, and even Railo 4.2. It also supports saving scripts as gists, and more. (It was also designed to go beyond just such code editing/execution to also be a place where tutorials would be shared and community events would be tracked, though at this writing in 2019, none of those are dated beyond 2015.)
CF2018 REST Playground feature, for testing REST calls
Finally, in the same vein of ways to “try things out”, CF 2018 adds still another means to do that with REST processing, in the new REST Playground feature.
This tool provides a new interactive way to work with CF REST services. It’s a web app bundled with the CF 2018 Admin, to help visualize, test, and debug REST services, as you can see above. It works with all REST apps currently registered to CF, and it can be used to create and then add/register REST apps into CF. It can be launched from the CF Admin “REST Services” page, or via a URL as :/restplay, though for security reasons that’s supported only via CF’s built-in web server only. It also does require that CF’s “developer profile” (added in CF2016) be enabled.
For more on the REST playground, including a several-screen walkthrough of using it, see these Adobe resources:
Coming up in part 5
In part 5, we’ll wrap up our focus on developer-oriented hidden gems by pointing out CFML language additions and enhancements in CF2018. But we won’t be done! There are still “other” hidden gems I’ll have to share beyond that. Until those, do check out the other parts so far, again as listed in the part 1 overview of the series.