Created
July 24, 2011 20:27
-
-
Save ibdknox/1103065 to your computer and use it in GitHub Desktop.
basic defpage
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
(defpage [:get ["/user/:id" :id #"\d+"]] {:keys [id]} | |
(str "You are user number " id)) |
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
(defpage "/error" [] | |
{:status 500 | |
:body "Oh no! An error has occurred"}) |
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
(defpage [:post "/login"] {:keys [username password]} | |
(str "You tried to login as " username " with the password " password)) |
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
(defpage [:post "/"] [] | |
"You posted here!") |
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
(pre-route "/admin/*" {} | |
(when-not (users/admin?) | |
(resp/redirect "/login"))) |
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
(defpage "/user/:id" {:keys [id]} | |
(str "You are user number " id)) |
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
;; A very simple page definition that maps to the root of your site. | |
(defpage "/" [] | |
"hello") |
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
(defpage [:get "/"] [] "This is a get") ;; same as (defpage "/" [] ..) | |
(defpage [:post "/"] [] "This is a post") | |
(defpage [:put "/"] [] "This is a put") | |
(defpage [:any "/"] [] "This is any request type") | |
;; and so on... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment