3

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
  • I've given up. Back to RPC style... RESTful and CF just don't go very well together. Too much work for too little return.
    – Henry
    Jun 3, 2010 at 1:52

7 Answers 7

3

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"
    };
}
1
  • 1
    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 3 By the way 3.0 is almost done, only a cache update and wirebox update,the rest of the core is feature complete. Jun 5, 2010 at 15:52
2

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.

1
2

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.

1
  • cool, thanks. Nice to know there're more RESTful framework for CF
    – Henry
    Jun 3, 2010 at 17:11
1

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! :)

0
1

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.

2
  • did you implement the PageController pattern in ColdFusion? Or what framework did you use that does this?
    – Henry
    Jun 2, 2010 at 3:01
  • No, it is my own framework in C#, but the MVC pattern is mostly universally applicable. Jun 2, 2010 at 3:21
0

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
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.