From a21ca7c08da2cf2f27c8db07af6e3785b27165ef Mon Sep 17 00:00:00 2001 From: Automatic build Date: Wed, 30 Jan 2019 14:27:09 +0000 Subject: [PATCH] Build book from commit 019082e2edf54f0d1344936de89ff43d8545c8c5 [skip ci] --- advanced/composing_routers.html | 2 +- advanced/configuring_routers.html | 2 +- advanced/dev_workflow.html | 2 +- advanced/different_routers.html | 2 +- advanced/route_validation.html | 2 +- advanced/shared_routes.html | 2 +- basics/name_based_routing.html | 2 +- basics/path_based_routing.html | 2 +- basics/route_conflicts.html | 2 +- basics/route_data.html | 2 +- basics/route_data_validation.html | 2 +- basics/route_syntax.html | 2 +- basics/router.html | 2 +- coercion/clojure_spec_coercion.html | 2 +- coercion/coercion.html | 2 +- coercion/data_spec_coercion.html | 2 +- coercion/schema_coercion.html | 2 +- development.html | 2 +- faq.html | 2 +- frontend/basics.html | 2 +- frontend/browser.html | 2 +- frontend/controllers.html | 2 +- http/default_interceptors.html | 2 +- http/interceptors.html | 2 +- http/pedestal.html | 2 +- http/sieppari.html | 2 +- http/transforming_interceptor_chain.html | 2 +- index.html | 2 +- performance.html | 2 +- ring/RESTful_form_methods.md | 36 ++++++++++++++++++++++++ ring/coercion.html | 2 +- ring/compiling_middleware.html | 2 +- ring/data_driven_middleware.html | 2 +- ring/default_handler.html | 2 +- ring/default_middleware.html | 2 +- ring/dynamic_extensions.html | 2 +- ring/middleware_registry.html | 2 +- ring/reverse_routing.html | 2 +- ring/ring.html | 2 +- ring/route_data_validation.html | 2 +- ring/slash_handler.html | 2 +- ring/static.html | 2 +- ring/swagger.html | 2 +- ring/transforming_middleware_chain.html | 2 +- 44 files changed, 79 insertions(+), 43 deletions(-) create mode 100644 ring/RESTful_form_methods.md diff --git a/advanced/composing_routers.html b/advanced/composing_routers.html index 540fcd9a..ee9223eb 100644 --- a/advanced/composing_routers.html +++ b/advanced/composing_routers.html @@ -1137,7 +1137,7 @@ diff --git a/advanced/configuring_routers.html b/advanced/configuring_routers.html index d452ce18..6cee4aec 100644 --- a/advanced/configuring_routers.html +++ b/advanced/configuring_routers.html @@ -843,7 +843,7 @@ diff --git a/advanced/dev_workflow.html b/advanced/dev_workflow.html index 1dbf765d..14ae08f1 100644 --- a/advanced/dev_workflow.html +++ b/advanced/dev_workflow.html @@ -902,7 +902,7 @@ diff --git a/advanced/different_routers.html b/advanced/different_routers.html index 7c14c221..9c17176b 100644 --- a/advanced/different_routers.html +++ b/advanced/different_routers.html @@ -850,7 +850,7 @@ diff --git a/advanced/route_validation.html b/advanced/route_validation.html index 1bedd100..68cc5700 100644 --- a/advanced/route_validation.html +++ b/advanced/route_validation.html @@ -938,7 +938,7 @@ diff --git a/advanced/shared_routes.html b/advanced/shared_routes.html index 6c8c5ca1..4af732e3 100644 --- a/advanced/shared_routes.html +++ b/advanced/shared_routes.html @@ -858,7 +858,7 @@ diff --git a/basics/name_based_routing.html b/basics/name_based_routing.html index 736f470c..62646ef2 100644 --- a/basics/name_based_routing.html +++ b/basics/name_based_routing.html @@ -861,7 +861,7 @@ diff --git a/basics/path_based_routing.html b/basics/path_based_routing.html index b4f5c7b3..f65262eb 100644 --- a/basics/path_based_routing.html +++ b/basics/path_based_routing.html @@ -819,7 +819,7 @@ diff --git a/basics/route_conflicts.html b/basics/route_conflicts.html index ad3f10f5..f67173e9 100644 --- a/basics/route_conflicts.html +++ b/basics/route_conflicts.html @@ -862,7 +862,7 @@ diff --git a/basics/route_data.html b/basics/route_data.html index cd73a8f0..a27f23a8 100644 --- a/basics/route_data.html +++ b/basics/route_data.html @@ -860,7 +860,7 @@ diff --git a/basics/route_data_validation.html b/basics/route_data_validation.html index 5c6ff0b9..d7b101f8 100644 --- a/basics/route_data_validation.html +++ b/basics/route_data_validation.html @@ -912,7 +912,7 @@ diff --git a/basics/route_syntax.html b/basics/route_syntax.html index 519165c1..eb355557 100644 --- a/basics/route_syntax.html +++ b/basics/route_syntax.html @@ -849,7 +849,7 @@ E.g., /foo bar should be /foo%20bar.

diff --git a/basics/router.html b/basics/router.html index b33124d4..55c5a028 100644 --- a/basics/router.html +++ b/basics/router.html @@ -829,7 +829,7 @@ diff --git a/coercion/clojure_spec_coercion.html b/coercion/clojure_spec_coercion.html index 26625e8a..ccb44bf8 100644 --- a/coercion/clojure_spec_coercion.html +++ b/coercion/clojure_spec_coercion.html @@ -836,7 +836,7 @@ diff --git a/coercion/coercion.html b/coercion/coercion.html index 43f727d9..283ee20c 100644 --- a/coercion/coercion.html +++ b/coercion/coercion.html @@ -926,7 +926,7 @@ diff --git a/coercion/data_spec_coercion.html b/coercion/data_spec_coercion.html index c8e7e383..804d19dd 100644 --- a/coercion/data_spec_coercion.html +++ b/coercion/data_spec_coercion.html @@ -825,7 +825,7 @@ diff --git a/coercion/schema_coercion.html b/coercion/schema_coercion.html index 1d5e64e9..b9da11a2 100644 --- a/coercion/schema_coercion.html +++ b/coercion/schema_coercion.html @@ -826,7 +826,7 @@ diff --git a/development.html b/development.html index 7f041156..53004e8a 100644 --- a/development.html +++ b/development.html @@ -816,7 +816,7 @@ lein test diff --git a/faq.html b/faq.html index f71de7dd..df75d0bf 100644 --- a/faq.html +++ b/faq.html @@ -894,7 +894,7 @@ diff --git a/frontend/basics.html b/frontend/basics.html index 94380251..f726bf46 100644 --- a/frontend/basics.html +++ b/frontend/basics.html @@ -804,7 +804,7 @@ React breaking due to errors). diff --git a/frontend/browser.html b/frontend/browser.html index 8f3f620a..795ddbd3 100644 --- a/frontend/browser.html +++ b/frontend/browser.html @@ -808,7 +808,7 @@ router instance and passes the instance to all calls.

diff --git a/frontend/controllers.html b/frontend/controllers.html index f897d796..37a9e550 100644 --- a/frontend/controllers.html +++ b/frontend/controllers.html @@ -892,7 +892,7 @@ missing resources.

diff --git a/http/default_interceptors.html b/http/default_interceptors.html index 807fdc93..39abfb0b 100644 --- a/http/default_interceptors.html +++ b/http/default_interceptors.html @@ -816,7 +816,7 @@ diff --git a/http/interceptors.html b/http/interceptors.html index 73e1936f..1f47958c 100644 --- a/http/interceptors.html +++ b/http/interceptors.html @@ -844,7 +844,7 @@ diff --git a/http/pedestal.html b/http/pedestal.html index 0ecdb853..469cf696 100644 --- a/http/pedestal.html +++ b/http/pedestal.html @@ -855,7 +855,7 @@ diff --git a/http/sieppari.html b/http/sieppari.html index 2be9cd8c..6b137766 100644 --- a/http/sieppari.html +++ b/http/sieppari.html @@ -856,7 +856,7 @@ diff --git a/http/transforming_interceptor_chain.html b/http/transforming_interceptor_chain.html index 2b49cdce..da4eabc8 100644 --- a/http/transforming_interceptor_chain.html +++ b/http/transforming_interceptor_chain.html @@ -855,7 +855,7 @@ diff --git a/index.html b/index.html index b3be587e..58a3725b 100644 --- a/index.html +++ b/index.html @@ -943,7 +943,7 @@ diff --git a/performance.html b/performance.html index cf71173c..d3c716b4 100644 --- a/performance.html +++ b/performance.html @@ -897,7 +897,7 @@ diff --git a/ring/RESTful_form_methods.md b/ring/RESTful_form_methods.md new file mode 100644 index 00000000..42185ade --- /dev/null +++ b/ring/RESTful_form_methods.md @@ -0,0 +1,36 @@ +# RESTful form methods + +When designing RESTful applications you will be doing a lot of "PATCH" and "DELETE" request, but most browsers don't support methods other than "GET" and "POST" when it comes to submitting forms. + +There is a pattern to solve this (pioneered by Rails) using a hidden "_method" field in the form and swapping out the "POST" method for whatever is in that field. + +We can do this with middleware in reitit like this: +```clj +(defn- hidden-method + [request] + (keyword + (or (get-in request [:form-params "_method"]) ;; look for "_method" field in :form-params + (get-in request [:multipart-params "_method"])))) ;; or in :multipart-params + +(def wrap-hidden-method + {:name ::wrap-hidden-method + :wrap (fn [handler] + (fn [request] + (if-let [fm (and (= :post (:request-method request)) ;; if this is a :post request + (hidden-method request))] ;; and there is a "_method" field + (handler (assoc request :request-method fm)) ;; replace :request-method + (handler request))))}) +``` + +And apply the middleware like this: +```clj +(reitit.ring/ring-handler + (reitit.ring/router ...) + (reitit.ring/create-default-handler) + {:middleware + [reitit.ring.middleware.parameters/parameters-middleware ;; needed to have :form-params in the request map + reitit.ring.middleware.multipart/multipart-middleware ;; needed to have :multipart-params in the request map + wrap-hidden-method]}) ;; our hidden method wrapper +``` +(NOTE: This middleware must be placed here and not inside the route data given to `reitit.ring/handler`. +This is so that our middleware is applied before reitit matches the request with a spesific handler using the wrong method.) diff --git a/ring/coercion.html b/ring/coercion.html index 8443ae99..487b8018 100644 --- a/ring/coercion.html +++ b/ring/coercion.html @@ -989,7 +989,7 @@ diff --git a/ring/compiling_middleware.html b/ring/compiling_middleware.html index 377c5222..b1ae5165 100644 --- a/ring/compiling_middleware.html +++ b/ring/compiling_middleware.html @@ -854,7 +854,7 @@ diff --git a/ring/data_driven_middleware.html b/ring/data_driven_middleware.html index b6f7ebdb..d40a2fcd 100644 --- a/ring/data_driven_middleware.html +++ b/ring/data_driven_middleware.html @@ -882,7 +882,7 @@ diff --git a/ring/default_handler.html b/ring/default_handler.html index e8b82a30..e3f6fac5 100644 --- a/ring/default_handler.html +++ b/ring/default_handler.html @@ -860,7 +860,7 @@ diff --git a/ring/default_middleware.html b/ring/default_middleware.html index 9e75f8a7..467feec7 100644 --- a/ring/default_middleware.html +++ b/ring/default_middleware.html @@ -1033,7 +1033,7 @@ Server: Jetty(9.2.21.v20170120) diff --git a/ring/dynamic_extensions.html b/ring/dynamic_extensions.html index c82484ee..5a4d44fd 100644 --- a/ring/dynamic_extensions.html +++ b/ring/dynamic_extensions.html @@ -829,7 +829,7 @@ diff --git a/ring/middleware_registry.html b/ring/middleware_registry.html index b528e533..497884f7 100644 --- a/ring/middleware_registry.html +++ b/ring/middleware_registry.html @@ -840,7 +840,7 @@ diff --git a/ring/reverse_routing.html b/ring/reverse_routing.html index fa290112..6e042ada 100644 --- a/ring/reverse_routing.html +++ b/ring/reverse_routing.html @@ -825,7 +825,7 @@ diff --git a/ring/ring.html b/ring/ring.html index e54c85c8..4f5d915f 100644 --- a/ring/ring.html +++ b/ring/ring.html @@ -969,7 +969,7 @@ diff --git a/ring/route_data_validation.html b/ring/route_data_validation.html index 307c858e..87793144 100644 --- a/ring/route_data_validation.html +++ b/ring/route_data_validation.html @@ -1037,7 +1037,7 @@ diff --git a/ring/slash_handler.html b/ring/slash_handler.html index a7de4b72..86ce3dc9 100644 --- a/ring/slash_handler.html +++ b/ring/slash_handler.html @@ -863,7 +863,7 @@ diff --git a/ring/static.html b/ring/static.html index 48cdcebc..71973e0e 100644 --- a/ring/static.html +++ b/ring/static.html @@ -865,7 +865,7 @@ diff --git a/ring/swagger.html b/ring/swagger.html index 88df1753..4969a124 100644 --- a/ring/swagger.html +++ b/ring/swagger.html @@ -1084,7 +1084,7 @@ see the next example diff --git a/ring/transforming_middleware_chain.html b/ring/transforming_middleware_chain.html index 988d819a..b9c5c6cc 100644 --- a/ring/transforming_middleware_chain.html +++ b/ring/transforming_middleware_chain.html @@ -846,7 +846,7 @@