Dart Uri authority
Syntax & Examples


Uri.authority property

The `authority` property in Dart's Uri class returns the authority component of the URI.


Syntax of Uri.authority

The syntax of Uri.authority property is:

 String authority 

This authority property of Uri returns the authority component.

Return Type

Uri.authority returns value of type String.



✐ Examples

1 Getting the authority from an HTTP URI

In this example,

  1. We parse an HTTP URI with authority 'example.com' and port '8080'.
  2. We access the `authority` property of the URI.
  3. We print the authority to standard output.

Dart Program

void main() {
  Uri uri = Uri.parse('https://example.com:8080/path?query=value');
  print(uri.authority);
}

Output

example.com:8080

2 Getting the authority from an FTP URI

In this example,

  1. We parse an FTP URI with user information and authority 'example.com'.
  2. We access the `authority` property of the URI.
  3. We print the authority to standard output.

Dart Program

void main() {
  Uri uri = Uri.parse('ftp://user:password@example.com');
  print(uri.authority);
}

Output

user:password@example.com

3 Getting the authority from a mailto URI

In this example,

  1. We parse a mailto URI with the authority 'user@example.com'.
  2. We access the `authority` property of the URI.
  3. We print the authority to standard output.

Dart Program

void main() {
  Uri uri = Uri.parse('mailto:user@example.com');
  print(uri.authority);
}

Output


Summary

In this Dart tutorial, we learned about authority property of Uri: the syntax and few working examples with output and detailed explanation for each example.