Giter Club home page Giter Club logo

Comments (1)

adityaathalye avatar adityaathalye commented on September 26, 2024

Hi! The following behaviour tripped me up, as someone trying out pedestal for the first time. I found this issue discussion while trying to figure out what was going on. It seems directly related to what I'm seeing, so I'm taking liberty to share my observation.

As of 0.7.0-beta1, pedestal does not disambiguate these two paths (excerpt from routes table printed to REPL).

:get /item/new           :com.example/new-item-page
:get /item/:item-id/view :com.example/view-item-page

Given the overlap of a static and a parameterised prefix (/item/new v/s/ /item/:item-id:), I believed the prefix-tree router would kick in and disambiguate these. However, in this case, pedestal matches /item/:item-id/view but returns "not found" for /item/new.

If I change the "view" route to /item/view/:item-id, then both routes match and work as expected.

A cursory experiment with prefix-tree as found in 0.7.0-beta1 makes me think the router should be able to disambiguate those overlapping routes and dispatch accordingly. If I have correctly understood the following, the insert/lookup pair appears to have the necessary information to do so. Or, at least, to complain to me about potentially conflicting routes.

(comment
  (require '[io.pedestal.http.route.prefix-tree :as iopt])

  ;; Try the same routes, in different orders

  (def ptree1 (-> nil
                  (iopt/insert "/item/:item-id/view" 1)
                  (iopt/insert "/item/new" 2)))

  (def ptree2 (-> nil
                  (iopt/insert "/item/new" 1)
                  (iopt/insert "/item/:item-id/view" 2)))

  ;; ptree1 looks like this

  {:wild? nil,
   :catch-all? nil,
   :segment "/item/",
   :param nil,
   :payload nil,
   :children
   {":"
    {:wild? true,
     :catch-all? nil,
     :segment ":item-id",
     :param :item-id,
     :payload nil,
     :children
     {"v"
      {:wild? nil,
       :catch-all? nil,
       :segment "view",
       :param nil,
       :payload {:routes [1]},
       :children nil}}},
    "n"
    {:wild? nil,
     :catch-all? nil,
     :segment "new",
     :param nil,
     :payload {:routes [2]},
     :children nil}}}

  ;; ptree2 looks like this

  {:wild? nil,
   :catch-all? nil,
   :segment "/item/",
   :param nil,
   :payload nil,
   :children
   {"n"
    {:wild? nil,
     :catch-all? nil,
     :segment "new",
     :param nil,
     :payload {:routes [1]},
     :children nil},
    ":"
    {:wild? true,
     :catch-all? nil,
     :segment ":item-id",
     :param :item-id,
     :payload nil,
     :children
     {"v"
      {:wild? nil,
       :catch-all? nil,
       :segment "view",
       :param nil,
       :payload {:routes [2]},
       :children nil}}}}}


  (iopt/lookup ptree1 "/item/new")
  ;; => {:path-params {:item-id "new"}, :payload nil}
  (iopt/lookup ptree2 "/item/new")
  ;; => {:path-params {:item-id "new"}, :payload nil}

  (iopt/lookup ptree1 "/item/:item-id/view")
  ;; => {:path-params {:item-id ":item-id"}, :payload {:routes [1]}}

  (iopt/lookup ptree2 "/item/:item-id/view")
  ;; => {:path-params {:item-id ":item-id"}, :payload {:routes [2]}}

  #_())

from pedestal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.