Manipulating & Parsing URLs


URL is the web standard interface to parse and manipulate URLs.

We can create a new object in a variety of ways In the most simple case we can simply just write the whole url
let url = new URL("");
Alternatively we are able to pass a (relative) url which will be automatically resolved to an absolute url
url = new URL("/manual/introduction", "");
To get the full url out of an object, we can check the href property
console.log(url.href); //
We are also able to get various other properties from the url. Here are a few examples of properties we have access to.
console.log(; //
console.log(url.origin); //
console.log(url.pathname); // /manual/introduction
console.log(url.protocol); // https:
When parsing a url we often need to read the search parameters.
url = new URL("");

console.log(url.searchParams.get("s")); // Deno.readFile
We're able to manipulate any of these parameters on the fly = "";
url.protocol = "http:";

console.log(url.href); //

Run this example locally using the Deno CLI:

deno run

Additional resources: