One Day of REST And Relaxation

Monday

A co-worker of mine has been absolutely fighting with CF10 REST to try and make it work. It is not working. It is fundamentally broken in several ways. I'll not list them all here. But, a few are: (Adding cfdump for diagnostics causes a 500. Trying to do authorization or error handling in the Application.cfc causes a 500. Changes to any CFC in the framework folder cause a 500.) Hmmm that sure is a lot of 500s. The final straw was it's tendency to start throwing 500 errors after it's been active for a while and nothing had changed.

Monday I came in and my co-worker informed me that she would NOT launch our internal REST API using CF10 REST. I agreed. We had a number of options. None of them were great. Based on the implementations of the current CF REST frameworks, I've been considering writing my own for weeks. I told our CTO that we could NOT launch with CF10 REST and that I thought I could build a REST framework in a day. (Crazy! I know.) He told me I had permission to do it if I could do it in the next 8 hours. After we had our developer meeting and I handled some other responsibilities, I got to start work on my framework at about 12 noon.

Here are some goals I wanted to achieve:

  • Write a clean lightweight framework that helped and didn't hinder you.
  • NOT require you to have an Application.cfc that extends one of my CFCs
  • NOT require you to write silly wrapper CFCs if you didn't need to.
  • Allow you to configure your resource handlers in a nice JSON packet.
  • Generally get out your way after that.

I speced the framework out. I created an epic in JIRA. I created a board named "One Day of REST" and a sprint called "Today!". I added my stories. I went and got a sugar-free Monster. I turned on some dubstep. I built my MXUnit text cfc full of failing tests. And then I wrote code and closed issues as fast as I could for the rest of the day. It was the most fun I have had for ages! I went home at 6:30pm with all my tests passing and a working demo running (and a programming high you wouldn't believe).

Tuesday

The next day I came in exhilarated and excited to hand my work off to my co-worker. I had her get latest from SVN and setup the example. While I was sitting there, we figured out the IIS URL rewrite. And she had the test running where she was going to put the final API code. I told her I was excited to see the first REST resource that she converted over and to let me know when it was done. She said, "Why don't we do it right now?". So, I said, "Sure.". After the hours and days and weeks she spent fighting CF10 REST, I watched her implement the first resource in about 48 seconds. It was amazing!

Our president walked by right about that time. My co-worker explained what was going on. He suggested we "sell" the framework to other shops. I suggested we "give" it to the community. He agreed. And thus was born "Relaxation".

See it on RIAForge

Comments
Adam Cameron's Gravatar Good stuff Chris!
I have to say I've only superficially looked @ REST stuff... mostly whilst testing ColdFusion 10. Your comments on Twitter y/day and the ensuring conversation certainly piqued my interest though.

And now I have a bunch of code to look at to compare your approach to ColdFusion 10's approach.

Tell me, other than the 500 buginess, do you have issue with ColdFusion's approach to it, or are you just fed up with its instability? So if Adobe fixed it all, would you be happy with it?

Cheers for all this work & encouraging me to look at REST, mate.

--
Adam
# Posted By Adam Cameron | 4/3/13 7:23 PM
Chris Phillips's Gravatar Even if they fixed it. I don't think I'd use it. It forces you to write a bunch of empty CFCs that mostly call services and return the results. And then the only way to really know all of your possible resource/verb routes would be to harvest the metadata from your folder of CFCs. I just don't like it.
# Posted By Chris Phillips | 4/3/13 7:41 PM
Michael Zock's Gravatar Why didn't she just do a quick Google search for alternatives, like Taffy?
http://fusiongrokker.com/post/taffy-a-restful-fram...

I've long since given up on many of ACF's features (e.g., their Hibernate integration, where a lot of advanced stuff is either missing or implemented incorrectly), but there are plenty of alternatives.
# Posted By Michael Zock | 4/4/13 2:45 AM
Adam Tuttle's Gravatar Congrats! I certainly know and enjoy that same buzz.

If you really want to make it a robust framework you should look through the closed issues for Taffy. There were a lot of little details that I wasn't aware of when I first started out that people eventually requested. Things like HTTP method tunneling, access-control-allow-origin headers, and so forth.

https://github.com/atuttle/Taffy/issues?milestone=...

Good luck!
# Posted By Adam Tuttle | 4/4/13 6:56 AM
Chris Phillips's Gravatar Michael,

Taffy is great. We did consider it. However please read the goals/requirements I had for the framework. Nothing out there (that I'm aware of) fits. So I wrote what I wanted.
# Posted By Chris Phillips | 4/4/13 6:58 AM
Chris Phillips's Gravatar Adam,

Thank you for sharing that. It definitely could help flesh out my little framework.

I don't plan on adding every feature that every user could possibly need. I just wanted a simple way to quickly expose methods on managed services as REST endpoints. Hopefully people can appreciate that Relaxation does that and lets you handle the rest.
# Posted By Chris Phillips | 4/4/13 7:06 AM
Jean Ducrot's Gravatar I concur with Michael, the only real options for doing REST with CF are Taffy on the flexible side and Coldbox if you are starting something from scratch. There is nothing you describe here that's not in both.
# Posted By Jean Ducrot | 4/4/13 7:13 AM
Chris Phillips's Gravatar Jean,

To the best of my knowledge:

CF10 REST requires you to create "special" CFCs and use meta-data to configure the request routing.

Taffy requires you to have an Application.cfc that extends the framework CFC AND create "special" CFCs that use meta-data and naming conventions to handle the request routing.

And ColdBox > Relax looks really nice if you want to (or are already using) ColdBox.

Powernap looks like it would require "special" CFCs that extend their base CFC and call a special method to return the results.

None of those frameworks satisfy the list of goals that we had (see list above). So, I wrote what we needed. If you don't think it is a "real" option and would prefer not to use it, I am totally OK with that.
# Posted By Chris Phillips | 4/4/13 9:20 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.6.002.