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 开发者_Python百科expose RESTful services easily?
Thanks
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"
};
}
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.
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.
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! :)
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.
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
Another option is Taffy (https://github.com/atuttle/Taffy). Add one CFC per URI template, and define a method for each HTTP method you want to support (GET, PUT, DELETE, etc).
<cfcomponent extends="taffy.core.resource" output="false"
taffy_uri="/user/{userID}/stuff/{stuffID}/property/{propertyID}">
<cffunction name="get" access="public" output="false">
...
</cffunction>
<cffunction name="post" access="public" output="false">
...
</cffunction>
<cffunction name="delete" access="public" output="false">
...
</cffunction>
</cfcomponent>
精彩评论