reitit/examples/ring-example/src/example/schema.clj

21 lines
905 B
Clojure
Raw Normal View History

2017-12-03 15:43:40 +00:00
(ns example.schema
(:require [schema.core :as s]
2017-12-09 20:49:32 +00:00
[reitit.ring.coercion-middleware :as coercion]
2017-12-03 15:43:40 +00:00
[reitit.ring.coercion.schema :as schema-coercion]))
(def routes
["/schema"
["/plus" {:name ::plus
:coercion schema-coercion/coercion
:responses {200 {:schema {:total s/Int}}}
:get {:summary "plus with query-params"
:parameters {:query {:x s/Int, :y s/Int}}
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200
:body {:total (+ x y)}})}
:post {:summary "plus with body-params"
:parameters {:body {:x s/Int, :y s/Int}}
:handler (fn [{{{:keys [x y]} :body} :parameters}]
{:status 200
:body {:total (+ x y)}})}}]])