I suppose this is a strange question to the huge majority of programmers that work daily with Java. I don't. I know Java-the-language, because I worked on Java projects, but not Java-the-world. I never made a web app from scratch in Java. If I have to do it with Python, Ruby, I know where to go (Django or Rails), but if I want to make a web application in Clojure, not because I'm forced to live in a Java world, but because I like the language and I want to give it a try, what libraries and frameworks should I use?
当前回答
另一个有趣的web服务器是Http-kit。它有很好的性能,是ring兼容的,并且也支持WebSockets。它主要是用clojure开发的,缺少Jetty/Tomcat中的一些奇怪的东西。
这很容易修补。
其他回答
如今,Pedestal是一个值得一看的框架。它是一个构建在Ring之上的服务器端框架,但是通过暂停和恢复特定的请求(否则缓慢的请求实际上会阻塞服务器线程),也可以从初始线程中释放传入的请求。可能有点像JavaBean。
其他很酷的框架还有hoplon。io和David Nolen的Om(基于React)
你也可以看看下面这些框架(摘自clojure/projects):
级联 召唤
关于Stack Overflow还有一个相关的问题:成熟的Clojure web框架?
声明:我是作者。
我把一个leiningen模板结合luminusweb和栗子模板。 所以你得到了一些东西,你可以用它来构建clojure代码以及前端和后端clojurescript代码。 此外,它还提供用户管理、一些简单的CRUD生成和一些更小的功能:https://github.com/sveri/closp
Compojure is no longer a complete framework for developing web applications. Since the 0.4 release, compojure has been broken off into several projects. Ring provides the foundation by abstracting away the HTTP request and response process. Ring will parse the incoming request and generate a map containing all of the parts of the request such as uri, server-name and request-method. The application will then handle the request and based on the request generate a response. A response is represented as a map containing the following keys: status, headers, and body. So a simple application would look like:
(def app [req]
(if (= "/home" (:uri req))
{:status 200
:body "<h3>Welcome Home</h3>"}
{:status 200
:body "<a href='/home'>Go Home!</a>"}))
One other part of Ring is the concept of middle-ware. This is code that sits between the handler and the incoming request and/or the outgoing response. Some built in middle-ware include sessions and stacktrace. The session middle-ware will add a :session key to the request map that contains all of the session info for the user making the request. If the :session key is present in the response map, it will be stored for the next request made by the current user. While the stack trace middle-ware will capture any exceptions that occur while processing the request and generate a stack trace that is sent back as the response if any exceptions do occur.
直接使用Ring可能会很乏味,所以Compojure是建立在Ring之上的,将细节抽象出来。应用程序现在可以用路由来表达,所以你可以有这样的东西:
(defroutes my-routes
(GET "/" [] "<h1>Hello all!</h1>")
(GET "/user/:id" [id] (str "<h1>Hello " id "</h1>")))
Compojure仍然在使用请求/响应映射,所以你可以在需要的时候访问它们:
(defroutes my-routes
(GET "*" {uri :uri}
{:staus 200 :body (str "The uri of the current page is: " uri)}))
在这种情况下,{uri:uri}部分访问请求映射中的:uri键,并将uri设置为该值。
最后一个组件是Hiccup,它使生成html更容易。各种html标记被表示为向量,第一个元素表示标记名,其余元素是标记体。"<h2>A header</h2>"变为[:h2 "A header "]。标记的属性位于可选映射中。"<a href='/login'>登录页面</a>"变为[:a {:href "/login"} "登录页面"]。下面是一个使用模板生成html的小示例。
(defn layout [title & body]
(html
[:head [:title title]]
[:body [:h1.header title] body]))
(defn say-hello [name]
(layout "Welcome Page" [:h3 (str "Hello " name)]))
(defn hiccup-routes
(GET "/user/:name" [name] (say-hello name)))
这里是compojure作者目前正在编写的一些文档的草稿的链接,您可能会发现这些文档很有用:compojure Doc
Reframe和om。接下来可能就是你要找的了。