diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index b64a1c09..8389b20b 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -28,6 +28,48 @@ pub type Uri { ) } +/// A constant representing an empty URI, useful as a starting point for constructing +/// URIs with minimal boilerplate. +/// +/// ## Examples +/// +/// ```gleam +/// let empty_uri = Uri.empty +/// // -> Uri( +/// // scheme: None, +/// // userinfo: None, +/// // host: None, +/// // port: None, +/// // path: "", +/// // query: None, +/// // fragment: None, +/// // ) +/// ``` +/// +/// ```gleam +/// // Create a URI by overriding only the needed fields: +/// let localhost_uri = Uri(..Uri.empty, scheme: Some("http"), host: Some("localhost")) +/// // -> Uri( +/// // scheme: Some("http"), +/// // userinfo: None, +/// // host: Some("localhost"), +/// // port: None, +/// // path: "", +/// // query: None, +/// // fragment: None, +/// // ) +/// ``` +/// +pub const empty = Uri( + scheme: None, + userinfo: None, + host: None, + port: None, + path: "", + query: None, + fragment: None, +) + /// Parses a compliant URI string into the `Uri` Type. /// If the string is not a valid URI string then an error is returned. ///