0

I just started learning some Clojure and i have some general questions about it, since i can't find anything about it in google.

  • I will create a website with clojure. How can i call a function on the website via an a-Tag or a button? Is this even possible? If not, how can i react to user interactions?
  • is it possible to pass data through clj files? I have experiance with Angular JS. There, if I want to share data, I just store it in a global factory and later I can just access it. Is this also possible in clojure? I don't want to use angular or JS in this application.
  • how can i get data from an url: /myroute/myId (car/5). I want to get the ID 5.

I hope you can understand my questions. Thanks in advance

Peter
  • 267
  • 2
  • 5
  • 14
  • These questions are kind of the least of your concerns in learning Clojure, imho. You should get your head around the functional paradigm first. Clojure and Clojurescript can do anything, so don't worry, just get your feet on the road and see where it takes you. :) – jmargolisvt Jul 20 '17 at 13:29
  • See also [this question](https://stackoverflow.com/questions/45228474/how-can-i-use-clojurescript-to-interact-with-the-html-dom) for a few pointers to get started in developing web apps in ClojureScript. – Toni Vanhala Jul 21 '17 at 06:32

2 Answers2

1

You can use Clojure to make a robust back end server. You can use a library such as compojure for routing. This enables you to transfer data via request and response maps. For the front end you can use Clojurescript (which unlike Clojure, runs on javascript). Clojurescript is not easy to set up until you are very comfortable with how projects are set up in Clojure.

The libraries and plugins that I definitely recommend are:

For Clojure (back end):

  • Ring
  • Compojure
  • clj-http or http-kit

For ClojureScript

  • figwheel
  • mandy1339
    • 496
    • 3
    • 11
    • thanks alot for all those informations. Right now, I'm abit more confused, though. I thought I could build a webpage either with clojure or clojure script. It seems I was wrong. My current "demo" project is a clojure project with compojure, ring and for HTML templating i use selmer. Can I just include clojure script in it?I'm trying to find a proper tutorial which explains me those two languages abit better. Do you maybe have some links which could be helpful for me? – Peter Jul 21 '17 at 07:29
    • I forgot another thing. If the frontend is in clojure script, which uses javascript, can google still index my page? I heared thats crawlers can't read JS since the page content is created directly at the clients browser. – Peter Jul 21 '17 at 10:34
    • So sorry for the late reply. With Clojure you can serve a static html files and you could just run a page with that. If you want to have logic and custom behavior on your page, you would need to use Javascript or clojurescript. Clojurescript is nice but not required. If you fear creating the content with Java/Clojure - script because of indexing, then create the content manually with html, and use scripting just for handling actions. So basically, Clojure > create back end server to serve html, perhaps other serverside logic, and Java/Clojure - script to handle custom behavior in your site. – mandy1339 Aug 15 '17 at 15:11
    • 1
      One more thing. With Compojure getting data through parameters is relatively easy, just read the compojure documentation: (GET "/user/:id" [id] (str "The user ID is " id)) https://github.com/weavejester/compojure/wiki/Destructuring-Syntax#compojure-specific-destructuring A great link to get started with ClojureScript is the following video: https://www.youtube.com/watch?v=wq6ctyZBb0A Reagent is like react: https://github.com/reagent-project/reagent-utils/blob/master/project.clj And remember to know Compojure you need to understand ring https://github.com/ring-clojure/ring/wiki – mandy1339 Aug 15 '17 at 15:16
    0

    I suggest you start off with learning the back-end (pure Clojure) and then move on to the front-end (ClojureScript). You could make a simple REST api using Compojure and use static HTML files to talk to them (or use Swagger).

    There are other and better (IMO) libraries for building web backends in Clojure out there, but Compojure is a good one if you're not very experienced yet.

    Don't jump to ClojureScript before you're comfortable enough with Clojure! Otherwise you'll get lost :-).

    Wout Neirynck
    • 314
    • 2
    • 4