Created
December 16, 2013 23:50
-
-
Save tastycode/7997307 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 shorty-clojure.handler | |
(:use compojure.core) | |
(:use ring.util.response) | |
(:require [compojure.handler :as handler] | |
[compojure.route :as route] | |
[ring.util.response :as resp] | |
[ring.middleware.json :as middleware] | |
[taoensso.carmine :as car :refer (wcar)])) | |
(def server-connection {:pool {:max-active 8} | |
:spec {:host "localhost" | |
:port 6379 | |
:timeout 4000}}) | |
(defmacro wcar* [& body] `(car/wcar server-connection ~@body)) | |
(defn uuid [] (str (java.util.UUID/randomUUID))) | |
(defn links-create [params] | |
(let [id (uuid)] | |
(let [link (assoc params "id" id)] | |
(wcar* (car/set id (:url params))) | |
(response link)) | |
)) | |
(defroutes app-routes | |
(GET "/:id" [id] (redirect-to-link id)) | |
(POST "/links" {params :params} (links-create params)) | |
(route/resources "/") | |
(route/not-found "Not Found")) | |
(def app | |
(-> | |
(handler/site app-routes) | |
(middleware/wrap-json-body) | |
(middleware/wrap-json-response))) |
This file contains hidden or 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
(defproject shorty-clojure "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:dependencies [ | |
[org.clojure/clojure "1.5.1"] | |
[compojure "1.1.6"] | |
[ring/ring-json "0.1.2"] | |
[c3p0/c3p0 "0.9.1.2"] | |
[cheshire "4.0.3"] | |
[com.taoensso/carmine "2.4.0"] | |
] | |
:plugins [[lein-ring "0.8.8"]] | |
:ring {:handler shorty-clojure.handler/app} | |
:profiles | |
{:dev {:dependencies [[ring-mock "0.1.5"]]}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment