moonuri

    RFC 3986 URI parsing, query parameters, percent encoding, path templates, and reference resolution

    uri
    url
    query
    rfc3986
    moonbit
    Download zip
    Version
    0.1.1
    License
    MIT
    Last updated
    3 hours ago
    Downloads
    2

    #MoonURI

    MoonBit 的 RFC 3986 URI/URL 基础库:解析、编码、Query 多值参数、相对引用合并和规范化。

    #功能

    • parse_uri:拆分 scheme、userinfo、host、port、path、query、fragment
    • IPv6 字面量 authority
    • parse_query / query_get_all:有序多值 Query
    • encode_component / decode_component:百分号编码
    • resolve_reference:相对引用合并
    • normalize_uri:scheme/host 小写和去点路径段
    • to_string:确定性重新序列化
    • match_path/users/{id} 路径模板
    • origin / same_origin / with_query / encode_query

    #示例

    let u = @moonuri.parse_uri("https://user@example.com:443/a?x=1#f").unwrap()
    let q = @moonuri.query_get_all(u.query(), "x")
    let n = @moonuri.normalize_uri(@moonuri.parse_uri("HTTP://EX.COM/a/./b/../c").unwrap())

    #边界

    不做 HTTP 客户端、Web 框架、路由注册、OpenAPI 校验或 HTTP mock。

    #验证

    moon fmt --check moon check --target wasm-gc --deny-warn moon test --target wasm-gc

    #许可证

    MIT

    Uri

    pub struct Uri {
    scheme : String
    userinfo : String
    host : String
    port : String
    path : String
    query : String
    fragment : String
    has_authority : Bool
    }

    RFC 3986 URI reference.

    Uri::fragment

    fn Uri::fragment(self : Uri) -> String

    Uri::has_authority

    fn Uri::has_authority(self : Uri) -> Bool

    Uri::host

    fn Uri::host(self : Uri) -> String

    Uri::path

    fn Uri::path(self : Uri) -> String

    Uri::port

    fn Uri::port(self : Uri) -> String

    Uri::query

    fn Uri::query(self : Uri) -> String

    Uri::scheme

    fn Uri::scheme(self : Uri) -> String

    Uri::userinfo

    fn Uri::userinfo(self : Uri) -> String

    decode_component

    fn decode_component(input : String) -> Result[String, String]

    encode_component

    fn encode_component(input : String) -> String

    encode_query

    fn encode_query(pairs : Array[(String, String)]) -> String

    is_absolute

    fn is_absolute(uri : Uri) -> Bool

    match_path

    fn match_path(pattern : String, path : String) -> Result[Array[(String, String)], String]

    Match /users/{id} style path templates. Literal segments must equal.

    normalize_uri

    fn normalize_uri(uri : Uri) -> Uri

    origin

    fn origin(uri : Uri) -> String

    parse_query

    fn parse_query(input : String) -> Result[Array[(String, String)], String]

    parse_uri

    fn parse_uri(input : String) -> Result[Uri, String]

    query_drop

    fn query_drop(input : String, key : String) -> Result[String, String]

    query_get_all

    fn query_get_all(input : String, key : String) -> Result[Array[String], String]

    query_has

    fn query_has(input : String, key : String) -> Bool

    remove_dot_segments

    fn remove_dot_segments(path : String) -> String

    resolve_reference

    fn resolve_reference(base : Uri, reference : Uri) -> Uri

    same_origin

    fn same_origin(a : Uri, b : Uri) -> Bool

    strip_fragment

    fn strip_fragment(uri : Uri) -> Uri

    to_string

    fn to_string(uri : Uri) -> String

    with_fragment

    fn with_fragment(uri : Uri, fragment : String) -> Uri

    with_path

    fn with_path(uri : Uri, path : String) -> Uri

    with_query

    fn with_query(uri : Uri, query : String) -> Uri

    Source Files