views:

279

answers:

6

Most CF MVC Frameworks use the front controller pattern. Usually Search Engine Safe (SES) plugin together with URL Rewrite are used to construct friendly URLs. However, when it comes to implementing RESTful services, using a MVC framework seems like a layer of complexity added on top of another layer of complexity.

How should one tame this beast? Any nice and clean approach of supporting RESTful services with ColdFusion? Any MVC framework out there that can expose RESTful services easily?

Thanks

+1  A: 

I use MVC as per Fowler's PageController pattern to implement REST services. One controller per resource and the controller implements a method for each of the http methods supported. i.e. GET, PUT, POST, DELETE.

Works well for me. The only area where my approach differs from the standard interpretation of MVC is that my model is really a model of the UI content. It's not a domain model. It may contain elements from the domain model, but it may also contain other content.

Darrel Miller
did you implement the PageController pattern in ColdFusion? Or what framework did you use that does this?
Henry
No, it is my own framework in C#, but the MVC pattern is mostly universally applicable.
Darrel Miller
+2  A: 

I have been using Powernap (http://powernap.riaforge.com) to implement RESTful web services. It's not an MVC framework, but I think it could work alongside whatever framework you're currently using in your app.

Ryan McIlmoyl
thx, I'll look into this
Henry
http://cfcommons.org/index.cfm/blog/2010/3/31/cfcommons-visuals--rest-web-services-with-powernap---part-1 video tutorial
Henry
+1  A: 

Funny you should ask. I am a fan of PowerNap, but I thought it could be done a little better another way, so I started my own framework last week. It's still a front-controller framework so everything is channeled through index.cfm (which is easily removed using url-rewriting), but it's built specifically for writing RESTful web services. It draws a lot of inspiration from PowerNap as well as FW/1.

It's still kind of rough, but it works. Right now I'd call it a proof of concept; but it doesn't have far to go before I call it version 1.0. I've put some information and the source on github.

Update 8/23/2010: Now officially at 1.0! :)

Adam Tuttle
+2  A: 

I tried using PowerNap a while ago, but I felt it didn't fit well with what I was doing (building an API on top of an existing application). My solution was RESTfulCF: it's front-controller, but doesn't implement full MVC, because (as you say) that's overkill.

We're currently using RESTfulCF to power a number of (heavy use) internal systems at White Label Dating, and it's running like a dream while allowing us to continue building the rest of the application separately from the API layer, which we use to expose just the systems we need.

Tim Blair
cool, thanks. Nice to know there're more RESTful framework for CF
Henry
A: 

Quicksilver is not bad! http://quicksilver.riaforge.org/

/**
* @url /hello/{text}
* @httpMethod GET
*/
public String function saySomething(required String text) {
return "Hello " & arguments.text;
}

Actual URL:

index.cfm/hello/developer
Henry
+3  A: 

ColdBox has been supporting RESTful URLs for a long time now. In 3.0 you can even split the incoming HTTP verbs to execute different actions in a nice decoupled manner. read here: http://blog.coldbox.org/post.cfm/coldbox-rest-enabled-urls

You can even have HTTP method security on your event handlers very easily:

component{

    this.allowedMethods = {
        LIST = "GET",
        SAVE = "POST,PUT"
    };
}
Luis Majano
how much RESTful support are there in 2.6.4? thanks
Henry
Henry, in 2.6.4 you have several things but not as complete as in 3.0, for example:- HTTP Verb SES action matching is only available in 3.0- SES regex constraints are only available in 3.0- HTTP Verb security is only in 3.0- Handler exception handling for REST is 3.0 only- RenderData to JSON,WDDX is 2.6 but native XML is 3.0- REST Resource caching is available in both 2.6 and 3- Request Context HTTP header and verb retrieval is only in 3By the way 3.0 is almost done, only a cache update and wirebox update,the rest of the core is feature complete.
Luis Majano