         (recur analyze-state' (next entries))
         ;; Final step is to sort the routes:
         (-> analyze-state first map->sorted-routes)))))
+
+(defn- invoke-leaf
+  "Attempts to identify a single endpoint to invoke based on the request method and what's in the dispatch map.
+
+  Returns a Ring response map (or a channel that will yield a response map, in async mode) or nil if there are no matching endpoints."
+  [request request-method request-path dispatch-map]
+  (let [potentials (concat (get dispatch-map request-method)
+                           (get dispatch-map :all))]
+    (case (count potentials)
+      1 (if-let [{:keys [handler route-params]} (first potentials)]
+          (-> request
+              (assoc :route-params (medley/map-vals (partial nth request-path) route-params))
+              handler))
+
+      ;; This is ok, it just means that the path mapped to some other method, but not
+      ;; any one matching an endpoint.
+      0 nil
+
+      ;; 2 or more is a problem, since there isn't a way to determine which to invoke.
+      (throw (ex-info (format "Request %s matched %d endpoints."
+                              (utils/summarize-request request)
+                              (count potentials))
+                      {:request   request
+                       :endpoints (map :endpoint potentials)})))))
 
 (defn- map-traversal-dispatcher
   "Returns a Ring handler using the given dispatch-map to guide

    (constantly ())))

(defn- add-dispatch-entries
  [dispatch-map method pathvec handler]
  (let [pathvec' (mapv #(if (variable? %) ::param %) pathvec)
        dispatch-path (conj pathvec' method)
        ;; maps keyword (from the route) to index into the path for the value.

    ;; This dispatch path is a vector of strings (or the ::param placeholder for a keyword
    ;; route parameter), terminated with a method keyword (:get, :put, etc., or :all). The
    ;; value is the leaf node, identifying the particular endpoint function to invoke.
    (update-in dispatch-map dispatch-path
               (fnil conj [])
               {:handler      handler
                :endpoint     (:function handler-meta)
                :route-params route-params})))

(defn- build-dispatch-map
  "Returns a dispatch-map for use with map-traversal-dispatcher."
