How can I parse a URL in Opal?

82 views Asked by At

Let's say I have a URL that I want to parse, including the query string:

https://www.example.com/foo?bar=1&a[]=x&a[]=y

I would expect to be able to obtain a hash of the query string like:

{ "bar" => "1", "a" => ["x", "y"] }

How can I parse this using Opal? I looked at options like URI and even CGI from Ruby, but it seems they are unavailable.

Clearly, I could break apart this string myself (or possibly use the Addressable gem), but I would like to use some included library function instead.

1

There are 1 answers

0
Benjamin Oakes On

hmdne on the Opal Slack has pointed me to opal-browser which includes the Browser::FormData.parse_query(s) method.