Created
June 21, 2011 22:20
-
-
Save ibdknox/1039072 to your computer and use it in GitHub Desktop.
get started step3
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
;;Create a page that lists out all our todos | |
(defpage "/todos" {} | |
(let [items (all-todos)] | |
(layout | |
[:h1 "Todo list!"] | |
(todos-list items)))) | |
;; Handle an HTTP POST to /todos, returning a | |
;; json object if successful | |
(defpage [:post "/todos"] {:keys [title due]} | |
(if-let [todo-id (add-todo title due)] | |
(response/json {:id todo-id | |
:title title | |
:due-date due}) | |
(response/empty))) | |
;; We can define route params too by making them | |
;; a keyword: /some/route/:param-name | |
(defpage "/todo/remove/:id" {todo-id :id} | |
(if (remove-todo todo-id) | |
(response/json {:id todo-id}) | |
(response/empty))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment