Get request Args


#1

I can’t seem to find a easy way to get the current requests args/params in a GET request without doing some weird regex. Is there a simple way to get them inside workers?

Basically when I get a request like example.com/page?foo=bar I want to check what foo is.


#2

Hi @jloh,

You can parse a URL using the URL class. Example:

let url = new URL(request.url)
if (url.searchParams.get("foo") == "bar") {
  // ...
}

Here’s a working example in the Workers Playground.