mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
resource -> endpoint
This commit is contained in:
parent
5796df494e
commit
4fa3e12b49
2 changed files with 7 additions and 7 deletions
|
|
@ -28,11 +28,11 @@
|
||||||
(update acc method expand opts)
|
(update acc method expand opts)
|
||||||
acc)) data http-methods)])
|
acc)) data http-methods)])
|
||||||
|
|
||||||
(defn compile-result [[path data] {::keys [default-options-resource] :as opts}]
|
(defn compile-result [[path data] {::keys [default-options-endpoint] :as opts}]
|
||||||
(let [[top childs] (group-keys data)
|
(let [[top childs] (group-keys data)
|
||||||
childs (cond-> childs
|
childs (cond-> childs
|
||||||
(and (not (:options childs)) (not (:handler top)) default-options-resource)
|
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
||||||
(assoc :options default-options-resource))
|
(assoc :options default-options-endpoint))
|
||||||
->endpoint (fn [p d m s]
|
->endpoint (fn [p d m s]
|
||||||
(-> (middleware/compile-result [p d] opts s)
|
(-> (middleware/compile-result [p d] opts s)
|
||||||
(map->Endpoint)
|
(map->Endpoint)
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
([request respond _]
|
([request respond _]
|
||||||
(respond (handle request))))))
|
(respond (handle request))))))
|
||||||
|
|
||||||
(def default-options-resource
|
(def default-options-endpoint
|
||||||
{:no-doc true
|
{:no-doc true
|
||||||
:handler default-options-handler})
|
:handler default-options-handler})
|
||||||
|
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
| ----------------------------------------|-------------
|
| ----------------------------------------|-------------
|
||||||
| `:reitit.middleware/transform` | Function or vector of functions of type `[Middleware] => [Middleware]` to transform the expanded Middleware (default: identity)
|
| `:reitit.middleware/transform` | Function or vector of functions of type `[Middleware] => [Middleware]` to transform the expanded Middleware (default: identity)
|
||||||
| `:reitit.middleware/registry` | Map of `keyword => IntoMiddleware` to replace keyword references into Middleware
|
| `:reitit.middleware/registry` | Map of `keyword => IntoMiddleware` to replace keyword references into Middleware
|
||||||
| `:reitit.ring/default-options-resource` | Default resource for `:options` method in endpoints (default: default-options-resource)
|
| `:reitit.ring/default-options-endpoint` | Default resource for `:options` method in endpoints (default: default-options-endpoint)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@
|
||||||
([data opts]
|
([data opts]
|
||||||
(let [opts (merge {:coerce coerce-handler
|
(let [opts (merge {:coerce coerce-handler
|
||||||
:compile compile-result
|
:compile compile-result
|
||||||
::default-options-resource default-options-resource}
|
::default-options-endpoint default-options-endpoint}
|
||||||
opts)]
|
opts)]
|
||||||
(r/router data opts))))
|
(r/router data opts))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@
|
||||||
[["/get" {:get (constantly response)}]
|
[["/get" {:get (constantly response)}]
|
||||||
["/options" {:options (constantly response)}]
|
["/options" {:options (constantly response)}]
|
||||||
["/any" (constantly response)]]
|
["/any" (constantly response)]]
|
||||||
{::ring/default-options-resource nil}))]
|
{::ring/default-options-endpoint nil}))]
|
||||||
|
|
||||||
(testing "endpoint with a non-options handler"
|
(testing "endpoint with a non-options handler"
|
||||||
(is (= response (app {:request-method :get, :uri "/get"})))
|
(is (= response (app {:request-method :get, :uri "/get"})))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue