Skip to content

Instantly share code, notes, and snippets.

@linuxsoares
Created January 27, 2018 13:25
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 linuxsoares/cbbb9798d3832a011b7a6cc29ab8d74f to your computer and use it in GitHub Desktop.
Save linuxsoares/cbbb9798d3832a011b7a6cc29ab8d74f to your computer and use it in GitHub Desktop.
(ns todo.handler
(:require [compojure.core :refer :all]
[compojure.handler :as handler]
[compojure.route :as route]
[ring.middleware.json :as json]
[ring.util.response :refer [response]]
[todo.query :refer :all]))
(defroutes app-routes
(GET "/api/todos" []
(response (get-todos)))
(GET "/api/todos/:id" [id]
(response (get-todo (Integer/parseInt id))))
(POST "/api/todos" {:keys [params]}
(let [{:keys [title description]} params]
(response (add-todo title description))))
(PUT "/api/todos/:id" [id title is_complete]
(response (update-todo (Integer/parseInt id) title is_complete)))
(DELETE "/api/todos/:id" [id]
(response (delete-todo (Integer/parseInt id))))
(route/resources "/")
(route/not-found "Not Found"))
(def app
(-> (handler/api app-routes)
(json/wrap-json-params)
(json/wrap-json-response)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment