Giter VIP home page Giter VIP logo

Comments (5)

rukor avatar rukor commented on August 18, 2024 22

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.

featheredtoast avatar featheredtoast commented on August 18, 2024 11

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.

lgrapenthin avatar lgrapenthin commented on August 18, 2024 1

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.

malcolmsparks avatar malcolmsparks commented on August 18, 2024

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.

awb99 avatar awb99 commented on August 18, 2024

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)

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.