Downcase hidden methods in RESTful example

- this documentation is mildly confusing when combined with hiccup's
  `form-to` since hiccup forcibly transforms the method specified in
  its convenience syntax: `(form-to [:delete "/my-url"] ... )` into an
  upper-case string:
  80e48352dd/src/hiccup/form.clj (L130)

- it's also common to get an upper-case string from elsewhere so it
  seems best to wrap the hidden `_method` in `lower-case`.
This commit is contained in:
Steven Deobald 2020-12-15 15:48:00 -06:00
parent 3a6985eb71
commit a3b251449b

View file

@ -8,9 +8,10 @@ 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
(keyword
(clojure.string/lower-case
(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