Comments (1)
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)
- Server Startup Error HOT 4
- io.pedestal.http.body-params/body-params could be more efficient HOT 1
- Terse syntax documentation is incomplete and confusing HOT 1
- Sample projects should be brought up to date, included in docs, built/tested with each PR or release
- Pedestal has a rarely used dependency on org.clojure.core.match that should be optional HOT 1
- clj-kondo configuration files should be packaged and distributed with associated libraries. HOT 1
- Proposal: remove the pedestal.aws library HOT 1
- 0.7.0: files and resources show up as "unrouted" in generated traces
- Jetty test uses deprecated method ServletContextHandler.setGzipHandler() HOT 1
- Allow a response map supplied by an interceptor to omit :headers and :body keys
- Better control of routing table printing for use in tests
- Spurious deprecation warnings in 0.7.0
- Master build failing after a release
- Minor issues in published 0.7.0 documentation
- Document release support strategy
- Pedestal 0.7 - README file is very out of date HOT 1
- WebSocket upgrade requests do not flow through the interceptor model
- Interceptors vs. Routes
- embedded template: show example using body params HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pedestal.