Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created April 3, 2014 15:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/9956196 to your computer and use it in GitHub Desktop.
Save sritchie/9956196 to your computer and use it in GitHub Desktop.
(ns paddleguru.middleware.request-method
(:require [clojure.string :as st]))
(defn ensure-request-method
"Middleware to ensure that the request method is properly processed
out of the form params. Without this, any ':delete' post that hits a
liberator endpoint will be processed as a :post.
(Compojure only processes this form-params field when you explicitly
list a route as (DELETE theroute [] handler).)"
[handler]
(fn [request]
(handler
(if-let [method (get-in request [:form-params "_method"])]
(assoc request :request-method (keyword (st/lower-case method)))
request))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment