Skip to content

Instantly share code, notes, and snippets.

@potix2
Created February 24, 2013 16:12
Show Gist options
  • Save potix2/5024367 to your computer and use it in GitHub Desktop.
Save potix2/5024367 to your computer and use it in GitHub Desktop.
compojure example
(ns adder.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]))
(defn parse-input [s]
(Integer. (re-find #"[0-9]*" s)))
(def fibs
((fn rfib
[a b]
(lazy-seq
(cons a (rfib b (+ a b)))))
0 1))
(defroutes app-routes
(GET "/add/:a/:b", [a b]
(str a " + " b " = " (+ (parse-input a) (parse-input b))))
(GET "/fib/:n", [n]
(str "fib[" n "] = " (nth fibs (parse-input n))))
(route/not-found "Not Found"))
(def app
(handler/site app-routes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment