-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.clj
28 lines (27 loc) · 1.26 KB
/
handler.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns example.handler
(:refer-clojure :exclude [list])
(:require
[compojure.route :as route]
[compojure.core :refer [routes GET POST ANY]]
[ring.util.response :refer [response content-type charset]]
[example.db :refer [save delete list]]
[example.api :refer [find-director]]))
(defn app-routes [{db :db}]
(routes
(GET "/" [] "Welcome. Feed a movie title, and get the director back. Info https://github.com/danielsz/system-advanced-example")
(POST "/movie" req (fn [{params :params :as req}]
(-> (pr-str {:director (find-director (:movie params))})
response
(content-type "application/edn")
(charset "UTF-8"))))
(GET "/directors" req (-> (pr-str (map :name (list db)))
response
(content-type "application/edn")
(charset "UTF-8")))
(ANY "/director" req (fn [{params :params :as req}]
(->
(case (:request-method req)
:put (save db (:director params))
:delete (delete db (:director params)))
response)))
(route/not-found "404")))