Fork me on GitHub
#reitit
<
2019-01-29
>
msolli09:01:32

Hi! I’m migrating from Compojure to Reitit, and looking for a way to make DELETE requests from HTML forms. In Compojure (as pioneered by Rails), you would add a hidden _method field (`<input type="hidden" value="DELETE">`) that would make the DELETE route handler to be invoked (see https://github.com/weavejester/compojure/blob/master/src/compojure/core.clj#L16). How do you make something like this happen in the Reitit world?

ikitommi10:01:50

@msolli I would do that outside of router via middleware: 1) mount the parameters middleware (and optionally the multipart middleware) via :middleware option in reitit.ring/ring-handler => needed to get access to :form-params & :multipart-params 2) add a custom middleware that overwrites the :request-method based on those, e.g. what compojure does 3) write a nice documentation page about this for future use

ikitommi10:01:34

something like:

(reitit.ring/ring-handler
  (reitit.ring/router ...)
  (reitit.ring/create-default-handler)
  {:middleware [reitit.ring.middleware.parameters/parameters-middleware 
                my-form-delete-change-request-method-middleware]})

msolli11:01:13

Kool, I see. I’ll make it work, and I’ll try to document it for the benefit of others. Would you accept a PR for https://github.com/metosin/reitit/tree/master/doc, and if so, which section?

ikitommi11:01:48

PR most welcome! It could be a separate page under doc/ring?

msolli11:01:02

Aight. A colleague will look into it, looks like. PR forthcoming.

kanwei20:01:34

how do you make :parameters with spec nilable?

kanwei20:01:50

:parameters  {:body {:key         (s/nilable spec/string?)
                                 :identifier            (s/nilable spec/string?)

kanwei20:01:31

get a coercion error regardless