ColdFusion MVC 框架和RESTful 服务不匹配?

发布于 2024-09-04 14:22:55 字数 219 浏览 4 评论 0原文

大多数 CF MVC 框架使用前端控制器模式。通常,搜索引擎安全 (SES) 插件与 URL 重写一起用于构建友好的 URL。然而,在实现 RESTful 服务时,使用 MVC 框架似乎是在另一层复杂性之上添加了一层复杂性。

该如何驯服这种猛兽呢?有什么好的、干净的方法来支持 ColdFusion 的 RESTful 服务吗?有没有可以轻松公开 RESTful 服务的 MVC 框架?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

枯寂 2024-09-11 14:22:55

ColdBox 长期以来一直支持 RESTful URL。在 3.0 中,您甚至可以拆分传入的 HTTP 动词,以良好的解耦方式执行不同的操作。阅读此处: http://blog.coldbox.org/post.cfm /coldbox-rest-enabled-urls

您甚至可以非常轻松地在事件处理程序上设置 HTTP 方法安全性:

component{

    this.allowedMethods = {
        LIST = "GET",
        SAVE = "POST,PUT"
    };
}

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"
    };
}
凉栀 2024-09-11 14:22:55

我一直在使用 Powernap (http://powernap.riaforge.com) 来实现 RESTful Web 服务。它不是 MVC 框架,但我认为它可以与您当前在应用程序中使用的任何框架一起工作。

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.

哆兒滾 2024-09-11 14:22:55

我不久前尝试使用 PowerNap,但我觉得它不太适合我正在做的事情(在现有应用程序之上构建 API)。我的解决方案是RESTfulCF:它是前端控制器,但没有实现完整的MVC,因为(正如你说)这太过分了。

我们目前正在使用 RESTfulCF 为 White Label Dating 的许多(大量使用)内部系统提供支持,它运行得像梦一样,同时允许我们继续与 API 层分开构建应用程序的其余部分,我们用 API 层来公开正是我们需要的系统。

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.

纵性 2024-09-11 14:22:55

有趣的是你应该问。我是 PowerNap 的粉丝,但我认为可以用另一种方式做得更好,所以我开始了我的上周自己的框架。它仍然是一个前端控制器框架,因此一切都通过 index.cfm 进行传输(可以使用 url 重写轻松删除),但它是专门为编写 RESTful Web 服务而构建的。它从 PowerNap 以及 FW/1 中汲取了很多灵感。

虽然还是有点粗糙,但是很有效。现在我将其称为概念验证;但不久之后我将其称为 1.0 版本。我已经放了一些信息github 上的源代码

2010 年 8 月 23 日更新:现在正式为 1.0! :)

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

指尖上得阳光 2024-09-11 14:22:55

我按照 Fowler 的 PageController 模式使用 MVC 来实现 REST 服务。每个资源一个控制器,控制器为每个支持的 http 方法实现一个方法。即获取、放置、发布、删除。

对我来说效果很好。我的方法与 MVC 标准解释的唯一不同之处在于我的模型实际上是 UI 内容的模型。它不是领域模型。它可能包含域模型中的元素,但也可能包含其他内容。

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.

谁的年少不轻狂 2024-09-11 14:22:55

水银也不错啊! http://quicksilver.riaforge.org/

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

实际网址:

index.cfm/hello/developer

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
你的背包 2024-09-11 14:22:55

另一种选择是太妃糖(https://github.com/atuttle/Taffy)。每个 URI 模板添加一个 CFC,并为您想要支持的每个 HTTP 方法(GET、PUT、DELETE 等)定义一个方法。

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文