成熟的 Clojure Web 框架? [英] Mature Clojure web frameworks?

查看:22
本文介绍了成熟的 Clojure Web 框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前成熟的 Clojure Web 框架有哪些选择?我正在寻找某种特征矩阵,告诉我流行的框架支持什么以及支持的程度,包括:

What are the current choices of mature Clojure web frameworks? I am looking for some kind of feature matrix telling me what the popular frameworks support and to what extent, including:

  • 响应模板(使用 Clojure 或其他标记编写的响应 - 例如带有 Tiles 的 JSP)
  • HTTP 会话
  • REST 将 URL 自动映射到操作函数和参数
  • HTML 表单(参数可用作地图、错误处理、验证)
  • 应用流程(从 Java 框架中得知 - 请求处理程序返回最终由渲染器处理的操作标识符)

推荐答案

也许 我的回答在 Clojure 中开发 RESTful Web 服务的良好起点是什么? 关于 SO 的问题可能是对你有帮助.它提到了 Clojure 的一些重要网络库(带有链接和简短摘要).我想在这里重申的关键点在该答案的第一段中陈述:

Perhaps my answer to the What is the good starting point to developing RESTful web service in Clojure? question on SO might be of help to you. It mentions some important web libraries for Clojure (with links and short summaries). The key point which I would like to reiterate here is stated in the first paragraph of that answer:

首先,我认为您不太可能在 Clojure 中找到一个单一的收缩包装解决方案来完成所有这些(除了通过互操作使用的 Java 库的形式).Clojure 的标准 Web 堆栈由许多库组成,人们以各种方式混合和匹配这些库(因为它们很容易完美兼容).

First of all, I think that you are unlikely to find a single shrinkwrapped solution to do all this in Clojure (except in the form of a Java library to be used through interop). What is becoming Clojure's standard Web stack comprises a number of libraries which people mix and match in all sorts of ways (since they happily tend to be perfectly compatible).

为此,我想补充一点,您可能不应该期望使用您可能从 Java 中了解的那种应用程序流"来处理事情(或者如果您认为您确实需要它,您可能不得不推出自己的库支持它!).不过没关系,因为人们似乎对 Ring 的处理程序即函数、高阶中间件友好的方法很满意.

To that I would add that you should probably not expect to handle things with the sort of "application flow" you might know from Java (or if you believe you really need it, you'll probably have to roll your own lib to support it!). That's alright, though, as people seem to be very happy with Ring's handler-is-a-function, higher-order-middleware-friendly approach.

解决您的问题:

  • Response templating:
    There is a number of Clojure-specific solutions, including Enlive and Hiccup (Enlive is a very powerful HTML scraping / templating / transforming engine; Hiccup is a DSL for writing HTML in Clojure with the nice property that it renders fast). Also, this is probably one place where it makes perfect sense to drop down to Java and use something like, say, StringTemplate. This even has the good side of discouraging the mixing of templates and logic! (I believe Stuart Halloway has mentioned that Relevance -- his company -- is using this strategy in their work and having great success with it.)

HTTP 会话
那将是
Sandbar,我想.作者已开始一系列博文看起来很有希望.

HTTP sessions
That would be Sandbar, I suppose. The author has started a series of blogposts about it which looks very promising.

具有将 URL 自动映射到操作函数和参数的 REST
那是 Ring &Compojure 和/或 小胡子.见下文.

REST with automatic mapping of URLs into action-functions and params
That's Ring & Compojure and/or Moustache. See below.

HTML 表单(参数可用作地图、错误处理、验证)
如上所述.

HTML forms (params available as map, error handling, validation)
As above.

应用程序流程(从 Java 框架中得知 - 请求处理程序返回最终由渲染器处理的操作标识符)
如上所述,人们通常不会在 Clojure 中执行某些操作.

Application flow (known from Java frameworks - request handlers return action identifiers which are eventually handled by renderers)
As mentioned above, not really something people tend to do in Clojure.

作为学习 Clojure 网络堆栈的起点,Ring 的作者 Mark McGranaghan 的 >本 Ring 教程 非常有帮助.Compojure 的作者 James Reeves 拥有 一些关于 Compojure 的文档.也许我最近的回答复合路线背后的大创意"? 问题也可能有帮助.Ring 的来源还包括一份很棒的 SPEC 文档.

As a starting point in learning about the Clojure web stack, this Ring tutorial by Ring's author Mark McGranaghan is very helpful. Compojure's author James Reeves has some documentation on Compojure. Perhaps my recent answer to the What’s the "big idea" behind compojure routes? question might be of help too. Ring's sources also include a great SPEC document.

这篇关于成熟的 Clojure Web 框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆