-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathhandler.clj
55 lines (48 loc) · 1.56 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(ns example.handler
"Asynchronous compojure-api application."
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[manifold.deferred :as d]
[clojure.core.async :as async]
compojure.api.async))
(def app
(api
{:swagger
{:ui "/"
:spec "/swagger.json"
:data {:info {:title "Simple"
:description "Compojure Api example"}
:tags [{:name "api", :description "some apis"}]}}}
(context "/api" []
:tags ["api"]
(GET "/plus" []
:return {:result Long}
:query-params [x :- Long, y :- Long]
:summary "adds two numbers together"
(ok {:result (+ x y)}))
(GET "/minus" []
:return {:result Long}
:query-params [x :- Long, y :- Long]
:summary "subtract two numbers from each other"
(fn [_ respond _]
(future
(respond (ok {:result (- x y)})))
nil))
(GET "/times" []
:return {:result Long}
:query-params [x :- Long, y :- Long]
:summary "multiply two numbers together"
(d/success-deferred
(ok {:result (* x y)})))
(GET "/divide" []
:return {:result Float}
:query-params [x :- Long, y :- Long]
:summary "divide two numbers together"
(async/go (ok {:result (float (/ x y))}))))
(context "/resource" []
(resource
{:responses {200 {:schema {:total Long}}}
:handler (fn [_ respond _]
(future
(respond (ok {:total 42})))
nil)}))))