Skip to content

Instantly share code, notes, and snippets.

@ibdknox
Created June 21, 2011 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibdknox/1039072 to your computer and use it in GitHub Desktop.
Save ibdknox/1039072 to your computer and use it in GitHub Desktop.
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