Benjamin Oakes
Benjamin Oakes

Reputation: 12782

How can I parse a URL in Opal?

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.

Upvotes: 0

Views: 89

Answers (1)

Benjamin Oakes
Benjamin Oakes

Reputation: 12782

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

Upvotes: 1

Related Questions