Skip to content

URL

URL parsing and field access. The Floe URL type is the same nominal URL as the runtime — passing a value to a TS function expecting URL is zero-cost.

FunctionSignatureDescription
URL.parse(string) -> Result<URL, ParseError>Parse a URL string. Returns Err on invalid input.
URL.href(URL) -> stringFull URL string
URL.origin(URL) -> stringprotocol://host
URL.protocol(URL) -> stringe.g. "https:" (note the colon)
URL.host(URL) -> stringhostname plus optional :port
URL.hostname(URL) -> stringJust the host, no port
URL.port(URL) -> stringPort as string, "" when default
URL.pathname(URL) -> stringPath component
URL.search(URL) -> stringQuery string including leading ?
URL.searchParams(URL) -> URLSearchParamsParsed query parameters
URL.hash(URL) -> stringFragment including leading #
URL.toString(URL) -> stringStringifies via href
match URL.parse("https://example.com/posts?id=42") {
Ok(u) -> {
let host = u |> URL.host // "example.com"
let path = u |> URL.pathname // "/posts"
let id = u |> URL.searchParams |> URLSearchParams.get("id")
Console.log(host, path, id)
},
Err(e) -> Console.error(e.message),
}

URL.parse is the only construction path — there is no URL("...") shorthand. The Result return type forces callers to handle malformed input rather than letting it throw at runtime.