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 #
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.
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.
The hostname
property of the URL interface is a string that represents the fully qualified domain name of the URL.
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
.
The password
property of the URL interface is a string that represents the password specified in the URL.
The pathname
property of the URL interface is a string that represents the path of the URL.
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.
The protocol
property of the URL interface is a string that represents the protocol scheme of the URL and includes a trailing :
.
The search
property of the URL interface is a string that represents the search string, or the query string, of the URL.
This includes the ?
character and the but excludes identifiers within the represented resource such as the URL.hash
. More granular control can be found using URL.searchParams
property.
#searchParams: URLSearchParams
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
Methods #
See #
variable URL
The URL interface represents an object providing static methods used for creating, parsing, and manipulating URLs.
Properties #
Methods #
Parses a URL string or URL object and returns a URL object.
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.