From 883a65acca44a925336dd0df599d90188cca861a Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Mon, 19 Nov 2018 21:04:38 +0200 Subject: [PATCH] Document the router options --- .../reitit-core/src/reitit/interceptor.cljc | 19 ++++++++------- .../reitit-core/src/reitit/middleware.cljc | 23 ++++++++----------- .../reitit-frontend/src/reitit/frontend.cljs | 2 +- modules/reitit-http/src/reitit/http.cljc | 20 +++++++--------- modules/reitit-ring/src/reitit/ring.cljc | 12 ++++------ 5 files changed, 33 insertions(+), 43 deletions(-) diff --git a/modules/reitit-core/src/reitit/interceptor.cljc b/modules/reitit-core/src/reitit/interceptor.cljc index c1829e49..1a2ff1fa 100644 --- a/modules/reitit-core/src/reitit/interceptor.cljc +++ b/modules/reitit-core/src/reitit/interceptor.cljc @@ -129,23 +129,22 @@ (defn router "Creates a [[reitit.core/Router]] from raw route data and optionally an options map with - support for Interceptors. See [docs](https://metosin.github.io/reitit/) for details. - - Example: - - (router - [\"/api\" {:interceptors [format-body oauth2]} - [\"/users\" {:interceptors [delete] - :handler get-user}]]) + support for Interceptors. See documentation on [[reitit.core/router]] for available options. + In addition, the following options are available: Options: | key | description | --------------------------------|------------- - | `:reitit.interceptor/transform` | Function of [Interceptor] => [Interceptor] to transform the expanded Interceptors (default: identity). + | `:reitit.interceptor/transform` | Function or vector of functions of type `[Interceptor] => [Interceptor]` to transform the expanded Interceptors (default: identity). | `:reitit.interceptor/registry` | Map of `keyword => IntoInterceptor` to replace keyword references into Interceptor - See router options from [[reitit.core/router]]." + Example: + + (router + [\"/api\" {:interceptors [format-body oauth2]} + [\"/users\" {:interceptors [delete] + :handler get-user}]])" ([data] (router data nil)) ([data opts] diff --git a/modules/reitit-core/src/reitit/middleware.cljc b/modules/reitit-core/src/reitit/middleware.cljc index d9bdc66d..1d70f314 100644 --- a/modules/reitit-core/src/reitit/middleware.cljc +++ b/modules/reitit-core/src/reitit/middleware.cljc @@ -122,23 +122,20 @@ (defn router "Creates a [[reitit.core/Router]] from raw route data and optionally an options map with - support for Middleware. See [docs](https://metosin.github.io/reitit/) for details. + support for Middleware. See documentation on [[reitit.core/router]] for available options. + In addition, the following options are available: + + | key | description + | -------------------------------|------------- + | `: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 Example: - (router - [\"/api\" {:middleware [wrap-format wrap-oauth2]} + (router + [\"/api\" {:middleware [wrap-format wrap-oauth2]} [\"/users\" {:middleware [wrap-delete] - :handler get-user}]]) - - Options: - - | key | description | - | -------------------------------|-------------| - | `:reitit.middleware/transform` | Function of `[Middleware] => [Middleware]` to transform the expanded Middleware (default: identity). - | `:reitit.middleware/registry` | Map of `keyword => IntoMiddleware` to replace keyword references into Middleware - - See other router options from [[reitit.core/router]]." + :handler get-user}]])" ([data] (router data nil)) ([data opts] diff --git a/modules/reitit-frontend/src/reitit/frontend.cljs b/modules/reitit-frontend/src/reitit/frontend.cljs index 7e714edc..8145404a 100644 --- a/modules/reitit-frontend/src/reitit/frontend.cljs +++ b/modules/reitit-frontend/src/reitit/frontend.cljs @@ -40,7 +40,7 @@ (defn router "Create a `reitit.core.router` from raw route data and optionally an options map. - Enables request coercion. See [[reitit.core.router]] for details on options." + Enables request coercion. See [[reitit.core/router]] for details on options." ([raw-routes] (router raw-routes {})) ([raw-routes opts] diff --git a/modules/reitit-http/src/reitit/http.cljc b/modules/reitit-http/src/reitit/http.cljc index bf307bd4..cb694b49 100644 --- a/modules/reitit-http/src/reitit/http.cljc +++ b/modules/reitit-http/src/reitit/http.cljc @@ -47,15 +47,13 @@ (defn router "Creates a [[reitit.core/Router]] from raw route data and optionally an options map with - support for http-methods and Interceptors. See [docs](https://metosin.github.io/reitit/) - for details. + support for http-methods and Interceptors. See documentation on [[reitit.core/router]] + for available options. In addition, the following options are available: - Options: - - | key | description | - | ---------------------------------------|-------------| - | `:reitit.interceptor/transform` | Function of `[Interceptor] => [Interceptor]` to transform the expanded Interceptors (default: identity). - | `:reitit.interceptor/registry` | Map of `keyword => IntoInterceptor` to replace keyword references into Interceptors + | key | description + | ---------------------------------------|------------- + | `:reitit.interceptor/transform` | Function or vector of functions of type `[Interceptor] => [Interceptor]` to transform the expanded Interceptors (default: identity) + | `:reitit.interceptor/registry` | Map of `keyword => IntoInterceptor` to replace keyword references into Interceptors | `:reitit.http/default-options-handler` | Default handler for `:options` method in endpoints (default: reitit.ring/default-options-handler) Example: @@ -65,9 +63,7 @@ [\"/users\" {:get get-user :post update-user :delete {:interceptors [delete-i] - :handler delete-user}}]]) - - See router options from [[reitit.core/router]] and [[reitit.middleware/router]]." + :handler delete-user}}]])" ([data] (router data nil)) ([data opts] @@ -112,7 +108,7 @@ | `:executor` | `reitit.interceptor.Executor` for the interceptor chain | `:interceptors` | Optional sequence of interceptors that are always run before any other interceptors, even for the default handler" ([router opts] - (ring-handler router nil opts)) + (ring-handler router nil opts)) ([router default-handler {:keys [executor interceptors]}] (let [default-handler (or default-handler (fn ([_]) ([_ respond _] (respond nil)))) default-queue (->> [default-handler] diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index 8d0a1989..42ebcd4f 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -67,14 +67,12 @@ (defn router "Creates a [[reitit.core/Router]] from raw route data and optionally an options map with - support for http-methods and Middleware. See [docs](https://metosin.github.io/reitit/) - for details. + support for http-methods and Middleware. See documentation on [[reitit.core/router]] for + available options. In addition, the following options are available: - Options: - - | key | description | - | ---------------------------------------|-------------| - | `:reitit.middleware/transform` | Function of `[Middleware] => [Middleware]` to transform the expanded Middleware (default: identity). + | key | description + | ---------------------------------------|------------- + | `: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.ring/default-options-handler` | Default handler for `:options` method in endpoints (default: default-options-handler)