mirror of
https://github.com/metosin/reitit.git
synced 2026-01-25 15:49:01 +00:00
commit
40efc2d9d4
1 changed files with 12 additions and 7 deletions
19
README.md
19
README.md
|
|
@ -85,24 +85,29 @@ Optionally, the parts can be required separately.
|
||||||
A Ring routing app with input & output coercion using [data-specs](https://github.com/metosin/spec-tools/blob/master/README.md#data-specs).
|
A Ring routing app with input & output coercion using [data-specs](https://github.com/metosin/spec-tools/blob/master/README.md#data-specs).
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
|
(require '[muuntaja.core :as m])
|
||||||
(require '[reitit.ring :as ring])
|
(require '[reitit.ring :as ring])
|
||||||
(require '[reitit.coercion.spec])
|
(require '[reitit.coercion.spec])
|
||||||
(require '[reitit.ring.coercion :as rrc])
|
(require '[reitit.ring.coercion :as rrc])
|
||||||
|
(require '[reitit.ring.middleware.muuntaja :as muuntaja])
|
||||||
|
(require '[reitit.ring.middleware.parameters :as parameters])
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(ring/ring-handler
|
(ring/ring-handler
|
||||||
(ring/router
|
(ring/router
|
||||||
["/api"
|
["/api"
|
||||||
["/math" {:get {:parameters {:query {:x int?, :y int?}}
|
["/math" {:get {:parameters {:query {:x int?, :y int?}}
|
||||||
:responses {200 {:body {:total pos-int?}}}
|
:responses {200 {:body {:total int?}}}
|
||||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body {:total (+ x y)}})}}]]
|
:body {:total (+ x y)}})}}]]
|
||||||
;; router data affecting all routes
|
;; router data affecting all routes
|
||||||
{:data {:coercion reitit.coercion.spec/coercion
|
{:data {:coercion reitit.coercion.spec/coercion
|
||||||
:middleware [rrc/coerce-exceptions-middleware
|
:muuntaja m/instance
|
||||||
|
:middleware [parameters/parameters-middleware
|
||||||
rrc/coerce-request-middleware
|
rrc/coerce-request-middleware
|
||||||
rrc/coerce-response-middleware]}})))
|
rrc/coerce-response-middleware
|
||||||
|
muuntaja/format-response-middleware]}})))
|
||||||
```
|
```
|
||||||
|
|
||||||
Valid request:
|
Valid request:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue