Skip to content

Instantly share code, notes, and snippets.

@ibdknox ibdknox/todos.clj
Created Jun 21, 2011

Embed
What would you like to do?
get started step3
;;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
You can’t perform that action at this time.