Comments (5)
Hi,
For use in CLJS, it would be nice to get the query params. I understand the rationale for not matching the uri pattern based on Q/params, but it should would be nice if it was part of the result of a match parsed into either a list of pairs or a multi-map
from bidi.
For those still looking to get around this on cljs, I ended up doing something like this (using cemerick.url
as a dependency to easily parse the query parameters.)
Ideally though, match-route should allow an option to return a map of the query params too!
(defn match-route-with-query-params
[route path & {:as options}]
(let [query-params (->> (:query (cemerick.url/url path))
(map (fn [[k v]] [(keyword k) v]))
(into {}))]
(-> (bidi/match-route* route path options)
(assoc :query-params query-params))))
from bidi.
Thanks. I agree with your rationale. My usecase is that I use bidi client side. There I don't have ring available. Obviously, I can and will just port the two necessary functions for parsing and emitting query strings, to have them available in individual handlers and build routes with them. Taking different dispatch routes based on them is obviously a bad idea, but that is also not what I was asking for :)
from bidi.
The query parameter routing was removed because it added quite a lot of complexity, which was compounded by the need to support both clojure and clojurescript targets. Query parameters are still passed in to handlers via the Ring request, as normal.
The bidi.ring/make-handler
function uses the :uri
of the request, which doesn't contain the query string. The query string will still be available in the :query-string
entry of the request, which you can parse into a map if necessary with ring.middleware.params/params-request
You shouldn't ever need to dispatch to different handlers based on the query-params. Query parameters are intended as extra parameters to pass to the handler, not to distinguish between handlers. When you form routes with path-for
you should create the path, then manually append your query-string if necessary.
But please let me know if this advice doesn't help you, and expand on your use-case in more detail. There could be other options to achieve what you need to do, and I'm very happy to support this in bidi directly if necessary. I just don't want to add special cases to bidi that encourage unintended uses of query parameters.
from bidi.
I also face the same issue with a reagent frontend app. The issue is that when you change the routing state (in other words, not change the url, but the other way around), then there are some handlers that need to know query params. So in cases like that, te bidirectional capacity of bidi breaks down.
from bidi.
Related Issues (20)
- Bidi brings older version of `ring-core` into projects; should it be :scope "provided"? HOT 1
- `just-path` removes # HOT 9
- Ring async handler support HOT 1
- X-Forwarded-Host is used over Host, can lead to security issues HOT 4
- Coercion around a route causes custom match extension records to be lost (affects vhosts) HOT 1
- Add Ataraxy in the comparison chart in the README.md
- compilation warnings (from a shadow-cljs project depending on [bidi "2.1.4"]) HOT 3
- Document uri-info better
- bidi.ring - alternates don't work
- Example with alpeh
- CLJS implementation does not parse longs properly
- Feature Request: Adding headers in a 307 redirect.
- Implementation of protocols for MultiFn HOT 2
- How to route to a pdf file
- Non-ASCII characters as path parameters
- Reflection warning on java.net.URLDecoder/decode
- resourcesMaybe no caching HOT 1
- filesmaybe missing
- Coercion on route path and query paramaters HOT 1
- Don't remove :handler from match-context
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 bidi.