URL Encoding in Deno

deno
Published on April 2, 2021

A url can be encoded in Deno by either using the encodeURI() method or creating a new URL object. No libraries are required to be imported.

  • Encoding a url with the standard Javascript encodeURI() method.

    let url = 'http://example.com?scope=email profile&url=http://google.com';
    
    // http://example.com/?scope=email%20profile&url=http://google.com
    let encoded_url = encodeURI(url);
    
  • Encoding a url by creating a new URL object.

    let url = 'http://example.com?scope=email profile&url=http://google.com';
    let url_ob = new URL(url);
    
    // http://example.com/?scope=email%20profile&url=http://google.com
    let encoded_url = url_ob.toString();
    
In this Tutorial