Created
July 11, 2016 16:45
-
-
Save yogsototh/7ae1911e54147e7d5ac43f1b377663f5 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 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