Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns linker.handler
  2.   (:require [compojure.core :refer :all]
  3.             [compojure.route :as route]
  4.             [ring.middleware.defaults :refer [wrap-defaults site-defaults]]))
  5.  
  6. (def link-storage {})
  7.  
  8. (defn new-link [req]
  9.   (let [params (:params req)
  10.         link (:link params)
  11.         hsh (hash link)]
  12.     (link-storage hsh link)
  13.     (str "Link: " hsh)))
  14.  
  15. (defn redirect [hsh]
  16.   (str "LINK: " (hsh link-storage)))
  17.  
  18. (defroutes app-routes
  19.   (GET "/" [] "Hello World")
  20.   (GET "/new-link" req new-link)
  21.   (GET "/:hsh" [hsh] (redirect hsh))
  22.   (route/not-found "Not Found"))
  23.  
  24. (def app
  25.   (wrap-defaults app-routes site-defaults))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement