Question

Starting with string "http://www.youtube.com/watch?v=P76Vbsk_3J0", I'd like to get {:v P76Vbsk_3J0}.

I am nearly there with:

(#'ring.middleware.params/parse-params "http://www.youtube.com/watch?v=P76Vbsk_3J0" "UTF-8")
=> {"http://www.youtube.com/watch?v" "P76Vbsk_3J0"}

(clojure.walk/keywordize-keys {"http://www.youtube.com/watch?v" "P76Vbsk_3J0"})
=> {:http://www.youtube.com/watch?v "P76Vbsk_3J0"}

Is there something I can grab from ring to get me the rest of the way there?

Was it helpful?

Solution

ring.middleware.params/parse-params expects only to receive a query parameter string so you need to remove everything before and including the ?, something like this will work:

(#'ring.middleware.params/parse-params
  (second (.split "http://www.youtube.com/watch?v=P76Vbsk_3J0" "\\?"))
  "UTF-8")
;=> {"v" "P76Vbsk_3J0"}

Note that you are using a function that is not a part of the public API.

OTHER TIPS

I'm not sure about what you are trying to do but the idiomatic ring way to do that is using ring.middleware.params/wrap-params and ring.middleware.keyword-params/wrap-keyword-params. Then the request map will contain a :param key with what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top