5 ms·
Does Clojure have a decent web framework?
by DeathArrow 3y ago
Does Clojure have a decent web framework?
- deleted 3y ago[deleted]
- gleenn 3y agoLuminus has been around a long time and Kit is newer. Most Clojurists believe in libraries over frameworks though so that's why you don't hear about web frameworks much. I've messed with Luminus a few times and it is really easy to pull out parts and swap in almost any bit of it. They document a lot well and make it really easy to pick different parts out of the gate like different DBs, JavaScript libs, and a lot more. The maintainer roams HN frequently as well :)
- gengstrand 3y agoWhatever happened to ring or donkey?
- gleenn 3y agoLuminus uses Ring.
- aphyr 3y agoAphyr.com is built with Luminus. :-)
- jwr 3y agoI am not sure what a web framework is, to be honest. The choices for many parts of a web application are really domain-specific and I'm not sure a single "framework" would work for everyone. As far as web-related components go, my app uses Rum (as an interface to React), ring, http-kit, pushy (for history manipulation), sente (for websockets), buddy (for authentication tools). If you are looking for a batteries-included "I want to have some sort of webapp right away" thing, I think https://kit-clj.github.io https://kit-clj.github.io would fit the bill, but the general feeling in the Clojure community is that unlike Python with Django or Ruby with Rails, the choice of app components is not predetermined by the language.
- 22289d 3y ago> I'm not sure a single "framework" would work for everyone. I guess you weren't lying because that is not what a web framework is. If it works for just me, that's a web framework. The fact that there are so many web frameworks shows that none work for everyone.
- spelufo 3y agoWhat about the database side of things?
- stefcoetzee 3y agonext.jdbc is the go-to library to interact with SQL databases. https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.894/doc/readme https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.8...
- jetrink 3y agoIf you don't need something as low-level as next.jdbc, HugSQL is my preferred library. It lets you write queries in .sql files, and the queries are then loaded as functions. If you want to dynamically generate queries, there are also libraries like HoneySQL.
- simongray 3y agoProbably worth mentioning that triplestores/Datomic-like databases are relatively mainstream in Clojure: https://github.com/simongray/clojure-graph-resources#datalog https://github.com/simongray/clojure-graph-resources#datalog
- shortrounddev2 3y agoComponents of a web framework: 1. Routing 2. ORM 3. Auth handling 4. Request middleware 5. Templating (if your application requires it) 6. User input validation Many other components that are escaping me right now
- PaulHoule 3y ago
- olavfosse 3y agohttps://biffweb.com/ https://biffweb.com/
- daveliepmann 3y agoIt has several. None of them dominate; most people assemble their own from individual libs.
- epgui 3y agoI know you’re probably going to think this answer is crazy or stupid, but you don’t need a web framework in clojure. In fact you don’t need all the libraries that many languages need.
- dgb23 3y agoComprehensive frameworks include: biff, kit. Both of these rely on some of the most popular and simple libraries for web dev. Most seem to simply use said libraries directly, mix and match what is needed. If you’re an experienced web developer but new to Clojure, then you’re going to spend a good weekend or so to set up a proper environment, combine the necessary libs and so on, if you have some guidance. The Clojure community is quite welcoming and helpful in that regard. There’s an initial learning curve, because it’s a functional Lisp though. That comes with some necessary re-wiring, but also with some unique powers. The cool thing about writing Clojure is that feeling: „Really that’s it?“ when you realize how simple it is. It’s also simply fun to use, because of how interactive it is.
- digdugdirk 3y agoDo you have any recommendations for good resources for a starting point? And maybe something like a generic "to-do app" style tutorial just to see how everything is laid out and how everything connects?
- stefcoetzee 3y agoConsider the tutorial on the Kit website: https://kit-clj.github.io/docs/guestbook.html#guestbook_application https://kit-clj.github.io/docs/guestbook.html#guestbook_appl...
- dgb23 3y agoThere are many good tutorials, free and paid books. However, if you just want to get started and have a minimal thing working without much fuss I recommend this one: https://clojure-doc.org/articles/tutorials/basic_web_development/ https://clojure-doc.org/articles/tutorials/basic_web_develop... I haven't directly used it but I reviewed it once and it seems to be one of the most straight forward and carefully written web development tutorials for Clojure. It uses a very minimal set of libraries and it really goes from A to Z. Perfect if you want to just get yourself familiar and have something working.
- digdugdirk 3y ago
- rafaelmn 3y agoBecause of it's lisp nature with special braces I find it to be nicer for creating DOM than HTML : [:div [:p "I am a component!"] [:p.someclass "I have " [:strong "bold"] [:span {:style {:color "red"}} " and red "] "text."]] really has that "first class" feel when you're working with it rather than feeling tacked on like JSX - at least that's how I remember it. My main problem with Clojure was the dynamic nature of it. I have not used it in very long time now (probably 7 years at this point) - but despite the amazing aspects of it I would not trade in TypeScript annotations. A question for clojurists here - what is the level of static type checking adoption in CLJ world ? When I was using it last time there were some things like schema validators, but nothing like TypeScript. It looks like there's static typing annotations support now but are the types widely used by popular projects/provided for big libraries ?
- jwr 3y agoFrom the point of view of a solo developer maintaining a large app over many years: I would not want to deal with static type checking and I would not find it useful, except for simpler subsets of my code. I do use spec, and I've used other checking solutions before. I also use :pre/:post conditions a lot, as well as plenty of assertions. But in a large and complex application the errors I'm likely to run into are not as simple as a mismatched type. My most valuable checks and specs constrain multiple data fields. Thinking about stuff I run into, I would say that the majority of errors are due to optionality — where a key is optional in some contexts, but mandatory in others.
- finnjohnsen2 3y ago"No, but maybe" is how I would answer this question myself. Maybe there is a working framework I'm unaware of - but in my experience using Clojure the last few years is that the concept of frameworks is not in the culture of the Clojure community. You compose your stack of smaller libs and build your own framework so to speak. The right questions in this context are; what http server to use, what routing lib is decent, what is a good lib for my database, what is a good lib for generating html from the server. etc. If you wanna start using clojure as a web server. Start with 'ring', and you can recieve http requests. You quickly realize you're missing stuff to do what you need and will go searching for libs. You'll find great libs out there for anything you ordinarily need for a web-server setup.
- yogsototh 3y agoLet me add my 2cents on this subject. I feel that due to its functional nature or perhaps this is just the community bias, Clojurists tend to prefer mixing lower level libraries to build their web application instead of relying on a specific big web framework like RoR for example. Luminus would be one RoR-like system. But today, I think people would probably choose reitit for the writing the API and use a clojurescript framework for the frontend or perhaps still use reitit to generate HTML pages using hiccup.