 (ns calfpath.internal
   (:require [clojure.string :as str]))
+
+
+(defn expected
+  ([expectation found]
+    (throw (IllegalArgumentException.
+             (format "Expected %s, but found (%s) %s" expectation (class found) (pr-str found)))))
+  ([pred expectation found]
+    (when-not (pred found)
+      (expected expectation found))))
 
 
 (defn parse-uri-template

    (and (vector? uri-pattern-or-template)
      (every? (some-fn string? keyword?)
        uri-pattern-or-template))          uri-pattern-or-template
    :otherwise (throw (IllegalArgumentException.
                        (str "Expected a string URI pattern or a parsed URI template, but found ("
                          (class uri-pattern-or-template) ") " (pr-str uri-pattern-or-template))))))


(def valid-method-keys #{:get :head :options :put :post :delete})

(defmacro method-dispatch
  ([method-keyword request expr]
    (when-not (valid-method-keys method-keyword)
      (expected (str "a method key (" valid-method-keys ")") method-keyword))
    (let [method-string (->> (name method-keyword)
                          str/upper-case)
          default-expr {:status 405
