URL API Reference

URL parsing, validation, and string conversion

Import

U std/url

Struct

S Url {
    scheme: String,    # Protocol (http, https, etc.)
    username: String,  # Optional username
    password: String,  # Optional password
    host: String,      # Hostname or IP
    port: i64,         # Port (0 if not specified)
    path: String,      # Path component
    query: String,     # Query string (without '?')
    fragment: String   # Fragment (without '#')
}

Methods

MethodSignatureDescription
newF new() -> UrlCreate empty URL
dropF drop(&self) -> i64Free all memory
to_stringF to_string(&self) -> StringConvert to string
full_pathF full_path(&self) -> StringGet full path (path + query + fragment)
default_portF default_port(&self) -> i64Get default port for scheme
effective_portF effective_port(&self) -> i64Get effective port (specified or default)
is_secureF is_secure(&self) -> i64Check if scheme is secure (https, ftps, wss)

Functions

FunctionSignatureDescription
url_parseF url_parse(s: String) -> OptionParse URL from String
url_parse_cstrF url_parse_cstr(cstr: i64) -> OptionParse URL from C string
url_to_stringF url_to_string(url: Url) -> i64Convert to C string (caller must free)
url_encodeF url_encode(s: String) -> StringURL-encode string (percent-encoding)
url_decodeF url_decode(s: String) -> StringURL-decode string (percent-decoding)

Usage

U std/url

F main() -> i64 {
    u := url_parse("https://example.com:8080/api?q=test#section")
    # u.scheme = "https", u.host = "example.com", u.port = 8080
    u.drop()
    0
}