Created
March 2, 2013 18:47
-
-
Save steveturner/5072487 to your computer and use it in GitHub Desktop.
app.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns startingclojure.app | |
(:use [clojure.pprint] [compojure.core] ) | |
(:require | |
[ring.adapter.jetty :as jetty] | |
[ring.util.response :as response] | |
)) | |
(defonce counter (atom 999)) | |
(defonce urls (atom {})) | |
(defn shorten | |
[url] | |
(let [id (swap! counter inc) | |
id (Long/toString id 36)] | |
(swap! urls assoc id url) | |
id)) | |
(defn homepage | |
[request] | |
(str @urls)) | |
(defn redirect | |
[id] | |
(response/redirect (@urls id))) | |
(defroutes app | |
(GET "/" request (homepage request)) | |
(GET "/:id" [id] (redirect id))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment