Clojure Pedestal: a real-time webapp library, not a Web Framework

One of the difficulties when choosing among frameworks or libraries is to understand what does the framework or library can, can’t or requires lots of effort to do. I’m currently settling for a technology to develop a small scale website. Since I’m fond of Clojure, I’ve heard some fuss over Pedestal. I decided to study it and give it a try.

For starter, some people call it a “Web Framework”, but after reading about it, I go along with one of its authors, Tim Ewald, who says it’s more of a library. (You can hear him speaking about it on Pedestal Podcast at 5:05). This clarification is really enlightening, for you should not expect Pedestal to be a fully featured CMS system with database integration, etc. etc., such as Django or RoR.

So what is Pedestal?

Pedestal is a Clojure tool to build internet applications requiring real-time collaboration and targeting multiple platforms. It provides a clean architecture for creating large, interactive, single-page applications in the browser.

In other words, the library empowers one to create interactive web-apps for multiple users. This is achieved through a cleverly designed message queuing system that transforms the model and renders a new view to the users:

app-with-emit

Overview of Pedestal inner-workings: users send message to the back end to transform the model. The messages are queued and applied to the model. Rendering function are then emitted to update the View.

This diagram illustrates the overall workings of the library. The users send their transformation messages to the back-end service. These messages are then queued and applied to the Info Model. Then rendering instructions are emitted so that the View is updated.

The library has additional functions to implement business logic when transforming the Model Info . For additional information see Derived Data and Continue Functions .

Bottom line is that Pedestal is not a Web Framework, but a powerful Clojure/Clojurescript library to tackle real-time web application with users interactions.

Advertisements

Clojure variadic map

When begining with Clojure, little by little you find out some snipets of code that enlighten and clean your code. One example I’ve encountered is when using map in function parameters, e.g.

(defn say-hi [{:keys [first-name last-name title]}]
   (print (str "Hello, " title " " last-name "!\n"
               "May I call you '" first-name "'?\n")))

So that it’s invocation is

=> (say-hi {:first-name "Murray" :last-name "Rothbard"
            :title "Mr."})
Hello, Mr. Rothbard!
May I call you 'Murray'?
;=> nil

But there is a cleaner way of doing it so, with just one “&” away:

(defn say-cleaner-hi [& {:keys [first-name last-name title]}]
   (print (str "Hello, " title " " last-name "!\n"
               "May I call you '" first-name "'?\n")))

Now the function call will be

(say-cleaner-hi :first-name "Murray" :last-name "Rothbard"
                :title "Mr.")
Hello, Mr. Rothbard!
May I call you 'Murray'?
;=> nil

Ain’t that pretty?