Newbie feedback on compojure/appengine-magic

35 views
Skip to first unread message

Vincent Liard

unread,
Apr 26, 2011, 9:46:21 AM4/26/11
to clojure...@googlegroups.com
Hi,

I've eventually managed to catch GET parameters with compojure but
I've had a hard time finding out the basics. I guess some clues could
be provided more obviously to help beginners. Here, I write down my
misunderstandings in case it could help improve the doc based on the
point of view of a hacker wannabe. For very-beginners, I also provide
a skeleton to get GET parameters.

1) My hard path

I've chosen clojure, appengine-magic and compojure to build a
webapp. Pretty ambitious given I'm new to all of them (but not totally
lisp-illiterate). I beg your pardon if I mix things up.

First, examples I found [*] were designed for clojure 0.4. I didn't
notice the version mismatch right away. When I realized it, I wondered
how to get a working example for 0.6. There is of course
https://github.com/weavejester/compojure/wiki/Getting-Started which is
good, but it says nothing about POST/GET parameters.

I found James Reeves message afterwards
http://groups.google.com/group/compojure/browse_thread/thread/56a2a9a885d5a651,
but I didn't undestand how to use the api function. Only long after
did I realize that it had to be called on the defoutes'd function.

I saw some messages on stackoverflow, especially
http://stackoverflow.com/questions/5024671/compojure-0-6-0-problem-getting-post-arguments-with-google-app-engine,
but it was not clear to me how def/defn/def-appengine-app are realated
and how to adapt the answer provided there. That's only when I came to
the "compojure.core/api" source code that I got a clue.

Lastly, I didn't expect the server to need a restart to get the
updated routes working. I now see it's the meaning of the first lines
of https://github.com/mmcgrana/ring/wiki/Interactive-Development,
which is referenced from the compojure wiki under Interactive
Development With Ring, but it didn't immediately occur to me.

Everything is not yet cristal clear to me, but at least do I have
something to experiment with.

2) A working skeleton

For other beginners, here is how to get something running with
appengine-magic 0.4.1 and compojure 0.6.2. The first steps are better
described on https://github.com/gcv/appengine-magic, chapter Getting
Started, section Project setup.

- "lein new dummy" will create a new leiningen project under directory
dummy

- edit dummy/project.clj to:

(defproject dummy "1.0.0-SNAPSHOT"
:description "Your project summary"
:dependencies [[org.clojure/clojure "1.2.1"]]
:dev-dependencies [[appengine-magic "0.4.1"]])

- delete the file dummy/src/core.clj

- "lein appengine-new" generates a new core.clj to match the appengine needs

- open dummy/src/core.clj, adapt it to:

(ns dummy.core
; I don't know yet what fits better under :use or :require
(:use compojure.core
hiccup.core)
(:require [appengine-magic.core :as ae]
[compojure.route :as route]
[compojure.handler :as handler]))

(defroutes dummy-app-handler
(GET "/" {params :params} (html params)) ; print out the parameters
(route/not-found "page not found"))

;; original definition as provided by ae-new
;; (ae/def-appengine-app dummy-app #'dummy-app-handler)
(ae/def-appengine-app dummy-app (api dummy-app-handler))

- from emacs, run swank clojure (that's how I do, probably not the
best advice to beginners)

- compile core.clj (C-c C-k)

- in the *slime-repl clojure* buffer, issue
(appengine-magic.core/serve dummy.core/dummy-app)

- the app should be available on http://localhost:8080/

I hope this journey was not too painful. I've tried to provide enough
detail about my mistakes so that someone can benefit from this to
improve the learning material. Anyway, I wouldn't end my message
without giving thanks to the community. I find it difficult to get
started but I see how great their work is and it keeps me on the
track!

Vincent


[*] Outdated examples and references:
http://stackoverflow.com/questions/3960356/what-is-the-good-starting-point-for-clojure-development-on-google-appengine
http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html
http://compojureongae.posterous.com/
http://cleancode.se/2010/09/03/getting-started-with-compojure2.html
http://en.wikibooks.org/wiki/Compojure/Getting_Started

James Reeves

unread,
Apr 26, 2011, 7:42:12 PM4/26/11
to clojure...@googlegroups.com
On 26 April 2011 14:46, Vincent Liard <vincen...@free.fr> wrote:
> First, examples I found [*] were designed for clojure 0.4. I didn't
> notice the version mismatch right away. When I realized it, I wondered
> how to get a working example for 0.6. There is of course
> https://github.com/weavejester/compojure/wiki/Getting-Started which is
> good, but it says nothing about POST/GET parameters.

The "Getting Started" page just contains the bare minimum instructions
to get started. Other pages on the wiki go into more detail, such as
this one:

https://github.com/weavejester/compojure/wiki/Destructuring-Syntax

If you want to get a feel for how a basic Compojure project is laid
out, there is an compojure-example project here:

https://github.com/weavejester/compojure-example

(It turns out this wasn't linked from the wiki, so I've added a link.)

It's important to realise that Compojure is just a thin routing layer
on top of Ring, so you really need to understand Ring first. I should
probably stop calling Compojure a "framework" on the project page, and
instead call it a "routing DSL".

The current state of Clojure web development is that there are a lot
of pieces without much "glue" to stick them together. I suspect that
will change before the end of the year, and tools will be developed
that will make starting a Clojure web project a lot easier. But we're
not quite there yet, I'm afraid, so currently you need to know the
individual libraries quite well, because there's no framework to do
that for you.

- James

Reply all
Reply to author
Forward
0 new messages