Module std::net::url

URL parsing.

Parse URLs into their components (scheme, host, port, path, query, fragment) and reconstruct or join them.

Examples

import std::net::url;

fn main() {
    let u = url.parse("https://example.com:8080/path?key=val#frag");
    println(u.host());
    println(u.port());
    u.free();
}

Contents

Functions

Function parse

pub fn parse(s: String) -> Url

Parse a URL string.

Panics if the string is not a valid URL.

Examples

let u = url.parse("https://example.com/api/v1");

Function encode

pub fn encode(s: String) -> String

Percent-encode a string (RFC 3986 unreserved characters are left unchanged).

Examples

import std::net::url;

let encoded = url.encode("hello world");  // "hello%20world"

Function decode

pub fn decode(s: String) -> String

Decode a percent-encoded string.

Returns an empty string on decode error.

Examples

import std::net::url;

let decoded = url.decode("hello%20world");  // "hello world"

Function encode_query

pub fn encode_query(params: String) -> String

Build a percent-encoded query string from a newline-separated list of key=value pairs.

Each line should be key=value. Lines without = are skipped. Pairs are joined with &.

Examples

import std::net::url;

let qs = url.encode_query("name=hello world\npage=1");
// "name=hello%20world&page=1"

Types

Struct Url

A parsed URL.

Created by url.parse(s). Must be freed with free() when no longer needed to avoid leaking memory.

Traits

Trait UrlMethods

Methods available on a parsed Url.

Methods

fn scheme(self: Url) -> String fn host(self: Url) -> String fn port(self: Url) -> i32 fn path(self: Url) -> String fn query(self: Url) -> String fn fragment(self: Url) -> String fn to_string(self: Url) -> String fn resolve(self: Url, path: String) -> Url fn free(self: Url)