Comparison of Clojure web frameworks [closed]
Asked Answered
L

6

67

There are a few web frameworks for Clojure

and also some libraries for dealing with certain web development subtasks, such as

  • Enlive for templating
  • Hiccup for templating
  • Ring to handle lower level stuff with requests/responses
  • ClojureQL for persistence (it doesn't seem very active, though)

There are also hundreds of Java libraries to be used. Some aspects were already discussed here and two of them compared a bit.

I wonder how these frameworks/components compare in terms of maturity, scope, ease of development, Django/RoR feeling, etc.

Lamee answered 24/7, 2010 at 12:13 Comment(2)
Don't forget to add Clojure on Coils at github.com/zubairq/coils and also PedestalPissed
Where does this stand today, nearing the end of 2013?Torture
P
41

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.

Palmette answered 24/7, 2010 at 12:28 Comment(6)
thanks for adding to the list of frameworks, Moustache is new to meLamee
@[Adam Schmideg] There are probably even more of them! Those are just all I can think of right now. They're certainly the most popular ones. :)Palmette
As for the update, Moustache is alive and well. It didn't really need any maintenance and I have been its happy user throughout all the changes in Clojure core. Christophe Grand is currently at work on releasing a new version, with a richer syntax and more features.Merkel
here is a link where the updated syntax is specified.Merkel
One more change: Noir as a framework is depreciated, the core parts moved to a library based on ring/compojure.Penelopa
It's been a while since this has been updated, is compojure still the recommended framework?Astrid
B
21

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!

Bingaman answered 8/7, 2011 at 4:52 Comment(1)
Noir is now deprecated, see: blog.raynes.me/blog/2012/12/13/moving-away-from-noir. The author recommends using Compojure instead.Gesture
M
11

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

Instead, consider using Compojure and lib-noir.

Medorra answered 26/3, 2013 at 20:19 Comment(0)
W
10

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.

Weald answered 7/3, 2015 at 9:52 Comment(0)
D
2

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.

Deianira answered 1/3, 2014 at 1:38 Comment(0)
T
2

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}))
Thornberry answered 8/3, 2015 at 3:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.