URIBuilder¶
Fluent builder for constructing URIs from raw (unencoded) components.
Each setter accepts raw text and automatically percent-encodes it for the
target component. The build() method validates the assembled URI and
returns a URI val.
match URIBuilder
.set_scheme("https")
.set_host("example.com")
.set_path("/api/users")
.add_query_param("name", "Jane Doe")
.set_fragment("top")
.build()
| let u: URI val =>
// u.string() == "https://example.com/api/users?name=Jane%20Doe#top"
| let e: URIBuildError val =>
// handle error
end
Use from() to copy an existing URI's pre-encoded components into the
builder for modification. Since from() copies pre-encoded values, do not
pass an existing URI's encoded component (e.g., uri.query) to a setter
like set_query() — that would double-encode it. Instead, use from()
and then modify only the components you want to change.
Constructors¶
create¶
Create an empty builder with all components unset.
Returns¶
- URIBuilder ref^
from¶
Copy pre-encoded components from an existing URI.
Authority components (userinfo, host, port) are decomposed from the URI's authority. All values are copied as-is without re-encoding.
Parameters¶
- uri: URI val
Returns¶
- URIBuilder ref^
Public Functions¶
set_scheme¶
Set the URI scheme from raw text.
The scheme is validated on build() — it must match
[A-Za-z][A-Za-z0-9+-.]* per RFC 3986 section 3.1. No encoding is
needed for schemes (they are ASCII-only).
Parameters¶
- scheme: String val
Returns¶
- URIBuilder ref
clear_scheme¶
Remove the scheme component.
Returns¶
- URIBuilder ref
set_userinfo¶
Set the userinfo component from raw (unencoded) text.
The input is percent-encoded for the userinfo component. If no host is set, an empty host is created automatically (userinfo requires an authority).
Parameters¶
- userinfo: String val
Returns¶
- URIBuilder ref
clear_userinfo¶
Remove the userinfo component.
Returns¶
- URIBuilder ref
set_host¶
Set the host component from raw (unencoded) text.
If the input starts with [, it is treated as an IP-literal and stored
as-is (validated on build()). Otherwise, it is percent-encoded as a
reg-name. IPv6 addresses must include brackets (e.g., [::1]).
Parameters¶
- host: String val
Returns¶
- URIBuilder ref
clear_host¶
Remove the host component.
Also clears userinfo and port, since they require an authority.
Returns¶
- URIBuilder ref
set_port¶
Set the port number.
If no host is set, an empty host is created automatically (port requires an authority).
Parameters¶
- port: U16 val
Returns¶
- URIBuilder ref
clear_port¶
Remove the port component.
Returns¶
- URIBuilder ref
set_path¶
Set the path component from raw (unencoded) text.
The input is percent-encoded for the path component. Path structure (slashes) is preserved — only characters that need encoding are encoded.
Parameters¶
- path: String val
Returns¶
- URIBuilder ref
append_path_segment¶
Append a single path segment from raw (unencoded) text.
The segment is encoded with slash (/) also encoded (as %2F) so
it remains a single segment. A / separator is prepended automatically.
Parameters¶
- segment: String val
Returns¶
- URIBuilder ref
set_query¶
Set the query component from raw (unencoded) text.
The input is percent-encoded for the query component. Structure characters
& and = are preserved since they are sub-delimiters allowed in query.
For individual key-value pairs with full encoding, use add_query_param.
Parameters¶
- query: String val
Returns¶
- URIBuilder ref
clear_query¶
Remove the query component.
After clearing, no ? delimiter appears in the output. To produce a
trailing ? with no value, use set_query("") instead.
Returns¶
- URIBuilder ref
add_query_param¶
Add a query parameter from raw (unencoded) key and value.
Both the key and value are encoded with =, &, and + also encoded
(in addition to standard query encoding) so they are safe as individual
parameter components. Parameters are appended with & as separator.
Parameters¶
Returns¶
- URIBuilder ref
set_fragment¶
Set the fragment component from raw (unencoded) text.
The input is percent-encoded for the fragment component.
Parameters¶
- fragment: String val
Returns¶
- URIBuilder ref
clear_fragment¶
Remove the fragment component.
After clearing, no # delimiter appears in the output. To produce a
trailing # with no value, use set_fragment("") instead.
Returns¶
- URIBuilder ref
build¶
Validate and assemble the URI from the current components.
Returns InvalidScheme if the scheme is set but does not match
[A-Za-z][A-Za-z0-9+-.]*. Returns InvalidHost if an IP-literal
host is malformed. Returns the assembled URI val on success.
Returns¶
- (URI val | InvalidScheme val | InvalidPort val | InvalidHost val)