deno.com

interface URL

The URL interface represents an object providing static methods used for creating, parsing, and manipulating URLs in Deno.

Use the URL API for safely parsing, constructing, normalizing, and encoding URLs. This is the preferred way to work with URLs in Deno rather than manual string manipulation which can lead to errors and security issues.

Properties #

#hash: string

The hash property of the URL interface is a string that starts with a # and is followed by the fragment identifier of the URL. It returns an empty string if the URL does not contain a fragment identifier.

#host: string

The host property of the URL interface is a string that includes the URL.hostname and the URL.port if one is specified in the URL includes by including a : followed by the port number.

#hostname: string

The hostname property of the URL interface is a string that represents the fully qualified domain name of the URL.

#href: string

The href property of the URL interface is a string that represents the complete URL.

#origin: string
readonly

The origin property of the URL interface is a string that represents the origin of the URL, that is the URL.protocol, URL.host, and URL.port.

#password: string

The password property of the URL interface is a string that represents the password specified in the URL.

#pathname: string

The pathname property of the URL interface is a string that represents the path of the URL.

#port: string

The port property of the URL interface is a string that represents the port of the URL if an explicit port has been specified in the URL.

#protocol: string

The protocol property of the URL interface is a string that represents the protocol scheme of the URL and includes a trailing :.

The searchParams property of the URL interface provides a direct interface to query parameters through a URLSearchParams object.

This property offers a convenient way to:

  • Parse URL query parameters
  • Manipulate query strings
  • Add, modify, or delete URL parameters
  • Work with form data in a URL-encoded format
  • Handle query string encoding/decoding automatically
#username: string

The username property of the URL interface is a string that represents the username of the URL.

Methods #

#toString(): string

The toString() method of the URL interface returns a string containing the complete URL.

#toJSON(): string

The toJSON() method of the URL interface returns a JSON representation of the URL.

See #

variable URL

The URL interface represents an object providing static methods used for creating, parsing, and manipulating URLs.

Properties #

#prototype: URL
readonly

Methods #

#parse(
url: string | URL,
base?: string | URL,
): URL | null

Parses a URL string or URL object and returns a URL object.

#canParse(
url: string | URL,
base?: string | URL,
): boolean

Returns a boolean value indicating if a URL string is valid and can be parsed.

#createObjectURL(blob: Blob): string

Creates a unique, temporary URL that represents a given Blob, File, or MediaSource object.

This method is particularly useful for:

  • Creating URLs for dynamically generated content
  • Working with blobs in a browser context
  • Creating workers from dynamically generated code
  • Setting up temporary URL references for file downloads

Note: Always call URL.revokeObjectURL() when you're done using the URL to prevent memory leaks.

#revokeObjectURL(url: string): void

Revokes a previously created object URL, freeing the memory associated with it.

Important for memory management in applications that create dynamic URLs. Once an object URL is revoked:

  • It can no longer be used to fetch the content it referenced
  • The browser/runtime is allowed to release the memory or resources associated with it
  • Workers created via the URL will continue to run, but the URL becomes invalid for new creations

For security and performance in Deno applications, always revoke object URLs as soon as they're no longer needed, especially when processing large files or generating many URLs.

See #