Clojure Web 框架的比较

发布于 2024-09-11 23:14:13 字数 1434 浏览 3 评论 0原文

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

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

发布评论

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

评论(6

﹉夏雨初晴づ 2024-09-18 23:14:13

当我第一次开始 Web 开发时,我使用的是 Clojure。我之前完全没有网络开发经验。我一生都无法弄清楚 Compojure。我不知道从那时起(不久前)初学者文档是否得到了改进,但当时我无法管理它。一位朋友向我推荐了 Mustache,在阅读了 README 后,我能够拼凑出什么是 http://try-clojure.org 处于当前状态。因此,就易用性而言,我认为 Mustache 更胜一筹。

但是,如果当时已存在,我可能会唱不同的曲子。

Conjure 看起来非常酷,尽管与其他框架非常不同。鉴于我在 Web 开发方面的经验非常有限,我在这件事上没有太多发言权,但 Conjure 对我来说有点不明确。只是感觉不对。可能只是我不习惯它做事的方式。

更新:自从我写这篇文章以来已经有一段时间了。很多事情都改变了。没有多少人再使用 Mustache,而且它也没有得到真正的积极维护,尽管它足够完整(并且足够简单),它可能仍然有效,但我现在建议使用 Compojure 或 Noir。这两个框架都是当前维护的框架,并且都非常擅长其工作。

更新 2:Noir 已被弃用相当长一段时间,其大部分功能已转移到一个库,该库旨在从 compojure/其他基于环的 Web 框架(称为 lib-noir.

When I first started with web development, it was with Clojure. I had no prior experience with web development at all. I could not, for the life of me, figure Compojure out. I don't know if beginner documentation has been improved since then (it wasn't that long ago) or not, but at the time, I couldn't manage it. A friend pointed me to Moustache and after reading the README, I was able to throw together what is http://try-clojure.org in it's current state. So, as far as ease of use goes, I think Moustache takes the cake for me.

However, if this has existed at the time, I might be singing a different tune.

Conjure looks very cool, though very different from the other frameworks. Given my very limited experience with web development in general, I don't have much say in this matter, but Conjure feels kind of unclojurey to me. It just doesn't feel right. It may just be that I'm not used to the way it does things.

UPDATE: It has been a while since I wrote this. Lots of things have changed. Not many people use Moustache anymore, and it isn't really actively maintained, though it was complete enough (and simple enough) that it probably still works, I'd now recommend going with Compojure or Noir instead. Both of these are currently maintained frameworks and both are excellent at their job.

UPDATE 2: Noir has been deprecated for quite a while and most of its functionality moved to a library designed to be used from compojure/other ring-based web frameworks called lib-noir.

那请放手 2024-09-18 23:14:13

我知道这个问题有点过时了......但我忍不住建议 Noir 作为一个非常好的选择。

Noir 使用 Ring、Compojure 和 Hiccup 的组合来完成这项工作。一探究竟!

I know this question is a bit dated... but I couldn't help but suggest Noir as a very nice option.

Noir uses a combination of Ring, Compojure, and Hiccup to get the job done. Check it out!

月竹挽风 2024-09-18 23:14:13

正如 Bjorn Lindqvist 的评论上面中提到的,Noir 已经死了。详细信息此处

相反,请考虑使用 Compojurelib-noir.

As mentioned in Bjorn Lindqvist's comment above, Noir is dead. Details here.

Instead, consider using Compojure and lib-noir.

一抹苦笑 2024-09-18 23:14:13

从框架的角度思考可能是一个错误。更好的方法是考虑将库组件组合在一起以获得最适合您的要求的“框架”。

我过去使用过很多框架。他们中的大多数都在让您快速启动和运行基本应用程序方面做得相当好。然而,无一例外,我发现他们都常常感到沮丧。通常,这是由于太多的样板文件或只是必须跳过与您开发的应用程序无关的障碍。

第一次接触 Clojure 时,我开始寻找框架,但后来意识到这是错误的方法。相反,我发现从基本的环应用程序开始,然后根据需要添加库要好得多。一开始,这似乎是一个更大的学习曲线,但事实上,它同样有效,因为您不必被迫学习一整堆您通常不需要的框架脚手架。

然而,我发现查看各种框架非常有用,因为它让我了解如何最好地集成库,更重要的是,在我看来,如何最好地构建 lein project.clj 文件以最适合您想要的工作流程。

我发现以下模板非常有用。我不会“按原样”使用其中任何一个,而是改编/窃取了其中许多想法来开发最适合我正在开发的应用程序的框架

  • LuminusLuminus 模板 提供了一个非常广泛的框架。我发现它们对于许多应用程序来说有点“重”,但是有一些很好的示例说明如何将各种 Clojure 库集成到您的应用程序中。主网站还有一些有用的文档。

  • Reagent 项目,其中包含一个试剂模板,为使用 Reagent (react.js) ClojureScript 支持的应用程序提供了一个良好的起点。我发现这是创建具有良好 Javascript 集成的应用程序的最简单的 ClojureScript 库之一。

  • lein-figwheel 是一个非常有趣的模板,使用 Figwheel 提供 clojurescript 的动态加载,以便您看到 ClojureScript 的更改当您修改代码时在浏览器中。许多其他模板现在已将此功能添加到自己的模板中。 Luminus 和 Reagent 模板最初是在考虑 Om 的情况下开发的,现在也在其模板中集成了 Figwheel 功能。真正展示了 Clojure 和 ClojureScript 对于交互式开发的一些好处。

  • Compojure 模板 是一个很好的起点。它建立了一个非常基本的基于 compojure 的项目,其中包含所有基本的环和 compojure 内容。开始 Clojure Web 开发的好方法,因为它很简单,并且允许您在被所有其他选项淹没之前专注于基础知识。

还有许多其他模板和框架,其中许多我还没有时间查看。如今,我经常从 compojure 模板或试剂模板开始,然后在需要时添加其他位。我通常还包括 selmar 作为模板,并使用与 Luminus 基本相同的配置。

也许为您的 Web 开发获得良好“框架”的最重要部分是试验并了解 lein 的工作原理以及 lein project.clj 文件。拥有一个好的project.clj 文件将决定您的工作流程。拥有正确的配置文件、以不同方式启动 repl 并加载不同库的能力(这些库允许您启动Figwheel 或浏览器repl 或生成jar 等)都是与您的project.clj 文件有关的。正确执行此操作,您的环境将提供您所需的工作流程。

Thinking in terms of frameworks is probably a mistake. The better approach is to think in terms of library components which you put together in order to have the 'framework' which best suits your requirements.

I have used a number of frameworks in the past. Most of them do a reasonably good job at getting you up and running with a basic application quite fast. However, without exception, I have found all of them just get frustrating more often than not. Often it is due to too much boilerplate or just having to jump through hoops which are not relevant for the application your developing.

When first coming to Clojure, I started looking for frameworks, but then realised this was the wrong approach. Instead, I found it much better to just start with a basic ring application and then add libraries as I needed them. This can seem like a bigger learning curve to start with, but in fact it turns out to be just as efficient because your not forced to learn a whole heap of framework scaffolding which you often don't need.

However,I have found looking at various frameworks really useful as it gives me ideas of how to best integrate a library and more importantly IMO, how you can best structure your lein project.clj file to best suit the workflow you want.

I've found the following templates really useful. I don't use any of them 'as is', but have adapted/stolen ideas from many of them to develop the frameworks which best suit the app I'm working on

  • Luminus and Luminus templates provides a very extensive framework. I find them a little 'heavy' for many applications, but there are some great examples of how to integrate various Clojure libraries into your app. The main website also has some useful documentation.

  • Reagent Project, which includes a reagent template provides a good starting point for an app using Reagent (react.js) ClojureScript support. I've found this to be one of the easiest ClojureScript libraries to create an app with good Javascript integration.

  • lein-figwheel is a really interesting template using figwheel to provide dynamic loading of clojurescript so that you see your ClojureScript changes in the browser as you modify your code. Many other templates have now added this functionality to their own templates. Originally developed with Om in mind, Luminus and Reagent templates now also integrate Figwheel functionality in their templates. Really shows some of the benefits of Clojure and ClojureScript for interactive development.

  • Compojure Template is a great starting point. It sets up a very basic compojure based project with all the basic ring and compojure stuff. Great way to start with Clojure web development because it is simple and allows you to focus on the basics before drowning under all the other options.

There are many other templates and frameworks, many of which I've not had time to look at yet. These days, I often start with either compojure template or reagent template and then add additional bits if and when required. I usually also include selmar for templates and use essentially the same configuration Luminus uses.

Perhaps the most important part of getting a good 'framework' for you web development is to experiment and understand how lein works and the lein project.clj file. Having a good project.clj file will determine your workflow. Having the right profiles, ability to start the repl in different ways and load different libraries which allow you to kick off figwheel or a browser repl or generate a jar etc is all about your project.clj file. Get this right and your environment will provide just the workflow you need.

不…忘初心 2024-09-18 23:14:13

作为实现 REST 服务的一个很好的替代方案,出现了一个新的参与者,它是 liberator。它可以更轻松地将您的数据公开为资源,同时自动遵守 HTTP 规范的所有相关要求 RFC- 2616 并与 http-kit 和 Compojure 配合良好。

顺便说一句,我对 http-kit 很满意,实时代码重新加载功能很方便。

A new player appeared in the scene as a good alternative to implement REST services is liberator. It makes easier to expose your data as resources while automatically complying with all the relevant requirements of the HTTP specification RFC-2616 and plays nicely with http-kit and Compojure.

Pretty happy with http-kit btw, the live code reload feature is handy.

残月升风 2024-09-18 23:14:13

尝试快速 Web 开发的道路框架
https://github.com/zhujinxian/road

(defn render-test [ret tmt]
  (-> (resp/response "------render----test------") 
    (#(resp/content-type %1 "text/plain"))))

(defn foo
  "I don't do a whole lot."
  [x]
  (str "来自源码目录的参数:" x))

(defn handler [^Integer x]
    {:$r render-test :text (str "hello world, road goes sucess!" (foo x))})

(defn home [req content ^Integer num]
    {:hiccup "home.clj" :content (str "home" content) :num num})

(defroad road (GET "/web-test-0.1.0-SNAPSHOT-standalone/main" handler) 
              (GET "/web-test-0.1.0-SNAPSHOT-standalone/home/:num{\\d+}" home))

(defn -main [& args]
  (log/info "---------log4j test-------")
  (jetty/run-jetty road {:port 3000}))

try road framework for fast web dev
https://github.com/zhujinxian/road

(defn render-test [ret tmt]
  (-> (resp/response "------render----test------") 
    (#(resp/content-type %1 "text/plain"))))

(defn foo
  "I don't do a whole lot."
  [x]
  (str "来自源码目录的参数:" x))

(defn handler [^Integer x]
    {:$r render-test :text (str "hello world, road goes sucess!" (foo x))})

(defn home [req content ^Integer num]
    {:hiccup "home.clj" :content (str "home" content) :num num})

(defroad road (GET "/web-test-0.1.0-SNAPSHOT-standalone/main" handler) 
              (GET "/web-test-0.1.0-SNAPSHOT-standalone/home/:num{\\d+}" home))

(defn -main [& args]
  (log/info "---------log4j test-------")
  (jetty/run-jetty road {:port 3000}))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文