Tech behind Tech

Raw information. No finesse :)

Compojure Demystified with an example – Part 2

with 2 comments


In part 1 I introduced the address book application that we are going to build.

In this part we will setup our skeleton project with compojure.

1) Install Leiningen

http://github.com/technomancy/leiningen/blob/master/README.md

2) Create a new project using Leiningen

lein new address_book

3) Add Compojure to our project:

a) Edit project.clj

(defproject address_book "1.0.0-SNAPSHOT"
  :description "Address Book"
  :dependencies [[org.clojure/clojure "1.1.0"]
                 [org.clojure/clojure-contrib "1.1.0"]
                 [compojure "0.4.1"]
                 [ring/ring-jetty-adapter "0.2.3"]])

b) Install dependencies

lein deps

This should install all dependencies of compojure

c) Test whether our setup is working

Edit src/address_book/core.clj

(ns address_book.core
  (:use [compojure.core]
           [ring.adapter.jetty])
  (:require [compojure.route :as route]))

(defroutes example
  (GET "/" [] "My Address Book!")
  (route/not-found "Page not found"))

(run-jetty example {:port 8080})

Run the server

lein repl src/address_book/core.clj

Goto http://localhost:8080 and you should see "My Address Book!"

In next part we will start implementing our functionalities.

Written by Siva Jagadeesan

August 15, 2010 at 6:49 pm

Posted in Clojure

Tagged with , ,

2 Responses

Subscribe to comments with RSS.

  1. The repl line doesn’t work any more :

    address_book% lein repl src/address_book/core.clj
    Wrong number of arguments to repl task.
    Expected ([] [project])

    It looks like the best way to achieve that is to add:
    :repl-init address_book.core
    to the project.clj file – then you can run “lein repl”.

    William Roe

    July 17, 2011 at 8:36 am

  2. I think the “lein repl…” command was supposed to be “lein run …” which would require a “:main address_book.core” entry into the project.clj

    Also, the “current” (at the time of writing) working set of versions for the libraries appearing above in the project.clj file are:

    :dependencies [[org.clojure/clojure "1.5.0"]
    [org.clojure/clojure-contrib "1.2.0"]
    [compojure "1.1.5"]
    [ring/ring-jetty-adapter "1.1.0"]]

    andee_marks

    May 27, 2013 at 11:47 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 146 other followers

%d bloggers like this: