Comparison of Clojure web frameworks

FrameworksClojureComparisonWeb Frameworks

Frameworks Problem Overview


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.

Frameworks Solutions


Solution 1 - Frameworks

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.

Solution 2 - Frameworks

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!

Solution 3 - Frameworks

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

Instead, consider using Compojure and lib-noir.

Solution 4 - Frameworks

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.

Solution 5 - Frameworks

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.

Solution 6 - Frameworks

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdam SchmidegView Question on Stackoverflow
Solution 1 - FrameworksRayneView Answer on Stackoverflow
Solution 2 - FrameworksNickSuperbView Answer on Stackoverflow
Solution 3 - FrameworksoverthinkView Answer on Stackoverflow
Solution 4 - FrameworksTim XView Answer on Stackoverflow
Solution 5 - FrameworksJaime AgudoView Answer on Stackoverflow
Solution 6 - Frameworksainixian2004View Answer on Stackoverflow