uri top-level property

Parser<({String? authority, String? fragment, String? hostname, List<(String, String?)> params, String? password, String path, String? port, String? query, String? scheme, String? username})> uri
final

A parser that decomposes an RFC-3986 URI into its constituent components.

Returns a record containing named fields for scheme, authority, username, password, hostname, port, path, query, params, and fragment.

For example:

final result = uri.parse('https://user:pass@example.com:8080/path?a=1&b=2#frag');
final value = result.value;
print(value.scheme);   // 'https'
print(value.hostname); // 'example.com'
print(value.port);     // '8080'
print(value.path);     // '/path'
print(value.params);   // [('a', '1'), ('b', '2')]

Implementation

final uri =
    seq5(
      _scheme.skip(after: ':'.toParser()).optional(),
      _authority.skip(before: '//'.toParser()).optional(),
      _path,
      _query.skip(before: '?'.toParser()).optional(),
      _fragment.skip(before: '#'.toParser()).optional(),
    ).map5((scheme, authority, path, query, fragment) {
      final auth = lib_authority.authority.parse(authority ?? '').value;
      final params = lib_query.query.parse(query ?? '').value;
      return (
        scheme: scheme,
        authority: authority,
        username: auth.username,
        password: auth.password,
        hostname: auth.hostname,
        port: auth.port,
        path: path,
        query: query,
        params: params,
        fragment: fragment,
      );
    });