Created
January 27, 2018 13:25
-
-
Save linuxsoares/cbbb9798d3832a011b7a6cc29ab8d74f to your computer and use it in GitHub Desktop.
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
(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