Sunday, June 9, 2013

Getting Started with Pedestal

I want to write a web app in clojure. I'll begin with picking a framework. I had played a little with Noir the last time I had picked up clojure. And now it has morphed into lib-noir. Other than that, there are also Luminus and Joodo. I picked Pedestal though, which caught my attention for its unique approach to clients. Pedestal seems to be a relatively immature framework, which also means I need to spend a lot more time and effort figuring out how to get going with it.

Implementing a service is easy enough, and well enough documented on the pedestal site.

mkdir ~/tmp
cd ~/tmp
lein new pedestal-service helloworld
cd helloworld

The documentation however doesn't cover how to get going with the client. I had to peek into clojars to get the equivalent:

mkdir ~/tmp
cd ~/tmp
lein new pedestal-app helloworld-app
cd helloworld

That this basic bit isn't documented should give you a sense for how far the documentation still has to go. The pedestal samples aren't very well documented, so it is rather hard to get a sense for how they're working. Here's what I have been able to figure out, in no particular order:
  • Like most web frameworks, the pedestal service receives a request, and produces a response to it, using an appropriate registered handler.
  • Unlike most web frameworks, a thread isn't tied to a request (and vice versa), which makes pedestal potentially much more flexible and efficient.
  • The client specification is written in the form of a dataflow, where an event is translated to an application state change, which in turn triggers a UI change.
  • The entire application state is captured by one (hidden) state object.
  • A client application created as above will give you a simple dev environment. You can easily interact with this dev environment. This is partially documented in the README for the helloworld sample. More documentation is available once you start the dev environment for a new project and go to http://localhost:3000/index.html
  • There doesn't seem to be a simple example on having a pedestal client communicate with a pedestal service. The chat client/server example is fairly complex, and will take a little time to boil down to the minimal messaging you can do between client and server.
  • Client and server applications are implemented and executed entirely independently of one another. For instance the chat sample requires you to link (or copy) the build result of the chat client into the server's resources.
  • I don't see why pedestal separates client and server lein templates. The client template after all includes some JVM-targeted clojure (as opposed to ClojureScript) to run a dev server. Why not have that dev server be a pedestal instance? This might help a great deal in getting started with building a coherent client/server application.
  • I don't know browser javascript APIs that well. And pedestal isn't going to help me with that lack of knowledge. This is entirely a personal problem that I didn't really expect pedestal to help with.
Given all these shortcomings, perhaps I shouldn't bother with pedestal. But I'm doing a hobby project to learn clojure better. And if the learning also brings along a different paradigm for thinking about web application programming, all the better. Pedestal to me is an experiment that I feel I would do well to learn from.