Skip to content

Instantly share code, notes, and snippets.

@yogsototh
Created July 11, 2016 16:45
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 yogsototh/7ae1911e54147e7d5ac43f1b377663f5 to your computer and use it in GitHub Desktop.
Save yogsototh/7ae1911e54147e7d5ac43f1b377663f5 to your computer and use it in GitHub Desktop.
(ns mtest.handler
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[schema.core :as s]))
(s/defschema Pizza
{:name s/Str
(s/optional-key :description) s/Str
:size (s/enum :L :M :S)
:origin {:country (s/enum :FI :PO)
:city s/Str}})
(defn wrap-print [handler]
(println "INIT HANDLER")
(fn [request]
(println "req")
(handler request)))
(def app
(api
{:swagger
{:ui "/"
:spec "/swagger.json"
:data {:info {:title "Mtest"
:description "Compojure Api example"}
:tags [{:name "api", :description "some apis"}]}}}
(context "/api" []
:middleware [wrap-print]
:tags ["api"]
(GET "/plus" []
:return {:result Long}
:query-params [x :- Long, y :- Long]
:summary "adds two numbers together"
(ok {:result (+ x y)}))
(POST "/echo" []
:return Pizza
:body [pizza Pizza]
:summary "echoes a Pizza"
(ok pizza)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment