mirror of
https://github.com/metosin/reitit.git
synced 2025-12-19 09:21:10 +00:00
Fix Ring example
Maybe it is not perfect solution but at least it works. It was somewhat weird that the front page of the lib contains non working examples.
This commit is contained in:
parent
1ab075bd35
commit
02004cac8d
1 changed files with 11 additions and 7 deletions
10
README.md
10
README.md
|
|
@ -85,24 +85,28 @@ 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]}})))
|
muuntaja/format-response-middleware]}})))
|
||||||
```
|
```
|
||||||
|
|
||||||
Valid request:
|
Valid request:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue