return json

This commit is contained in:
Tommi Reiman 2018-09-03 18:52:57 +03:00
parent 13ceab524d
commit 048f7e48b6
2 changed files with 11 additions and 7 deletions

View file

@ -3,18 +3,19 @@
[reitit.ring :as ring]
[reitit.interceptor.sieppari]
[ring.adapter.jetty :as jetty]
[muuntaja.interceptor]
[clojure.core.async :as a]
[manifold.deferred :as d]
[promesa.core :as p]))
(defn interceptor [f x]
{:enter (fn [ctx] (f (update-in ctx [:request :via] (fnil conj []) x)))
:leave (fn [ctx] (f (update-in ctx [:response :body] str "\n<- " x)))})
{:enter (fn [ctx] (f (update-in ctx [:request :via] (fnil conj []) {:enter x})))
:leave (fn [ctx] (f (update-in ctx [:response :body] conj {:leave x})))})
(defn handler [f]
(fn [{:keys [via]}]
(f {:status 200,
:body (str (apply str (map #(str "-> " % "\n") via)) " hello!")})))
:body (conj via :handler)})))
(def <sync> identity)
(def <future> #(future %))
@ -54,7 +55,8 @@
:handler (handler <promesa>)}}]])
(ring/create-default-handler)
{:executor reitit.interceptor.sieppari/executor}))
{:executor reitit.interceptor.sieppari/executor
:interceptors [(muuntaja.interceptor/format-interceptor)]}))
(defn start []
(jetty/run-jetty #'app {:port 3000, :join? false, :async? true})

View file

@ -26,10 +26,11 @@
["/upload"
{:post {:summary "upload a file"
:parameters {:multipart {:file multipart/temp-file-part}}
:responses {200 {:body {:file multipart/temp-file-part}}}
:responses {200 {:body {:name string?, :size int?}}}
:handler (fn [{{{:keys [file]} :multipart} :parameters}]
{:status 200
:body {:file file}})}}]
:body {:name (:filename file)
:size (:size file)}})}}]
["/download"
{:get {:summary "downloads a file"
@ -37,7 +38,8 @@
:handler (fn [_]
{:status 200
:headers {"Content-Type" "image/png"}
:body (io/input-stream (io/resource "reitit.png"))})}}]]
:body (io/input-stream
(io/resource "reitit.png"))})}}]]
["/math"
{:swagger {:tags ["math"]}}