Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Stdlib

Uri

new Uri(url).Scheme / .Host / .Port / .AbsolutePath / .PathAndQuery / .Query / .Fragment

Parse a URL into its parts with the C#-faithful `new Uri(url)` handle. Construct it from a URL string, then read `.Scheme`, `.Host`, `.Port`, `.AbsolutePath`, `.PathAndQuery`, `.Query`, and `.Fragment`. Pure — no capability needed. Pairs with the HTTP surface (parse a webhook or redirect URL).

stable2 examples compiled by CIuriurlparsingbcl

Summary#

Uri is the parsed-URL handle, spelled exactly as in C#. Construct it from a URL string and read its parts:

var u = new Uri("https://api.example.com:8443/v1/users?active=true#top");
u.Scheme;         // "https"
u.Host;           // "api.example.com"
u.Port;           // 8443
u.AbsolutePath;   // "/v1/users"
u.PathAndQuery;   // "/v1/users?active=true"
u.Query;          // "?active=true"
u.Fragment;       // "#top"

It is pure — no capability, no using required. Uri is also where the URL-escaping helpers live (Encoding — Base64, URL, HTMLUri.EscapeDataString), exactly as C#'s System.Uri carries both.

Signature#

Uri     new Uri(string url)      // parse an ABSOLUTE URL

string  uri.Scheme               // "https"
string  uri.Host                 // "api.example.com"
int     uri.Port                 // 8443 (or the scheme default: 443 for https, 80 for http)
string  uri.AbsolutePath         // "/v1/users"
string  uri.PathAndQuery         // "/v1/users?active=true"
string  uri.Query                // "?active=true" (empty when there is none)
string  uri.Fragment             // "#top" (empty when there is none)

Description#

new Uri(url) parses an absolute URL once and exposes its components as instance members — the same shape as C#'s System.Uri. When the URL omits the port, .Port is the scheme's default (443 for https, 80 for http). .Query and .Fragment include their leading ? / #, and are empty strings when absent.

An invalid or relative URL throws — new Uri parses an absolute URI, faithful to C#. Validate untrusted input first (e.g. with Regex) if a throw is not what you want.

Examples#

Route on the host of a webhook URL, parsing an Http.* target:

bool IsTrustedHost(string webhookUrl) {
  var u = new Uri(webhookUrl);
  return u.Scheme == "https" && Text.EndsWith(u.Host, ".example.com");
}

Build a URL with an escaped query value (Encoding — Base64, URL, HTML) and read it back:

Uri Search(string term) {
  return new Uri("https://api.example.com/search?q=" + Uri.EscapeDataString(term));
}

See also#

  • Encoding — Base64, URL, HTMLUri.EscapeDataString / UnescapeDataString for building the URL you parse
  • Http.* — the outbound HTTP surface whose URLs this parses
  • Regex — validate a URL string before parsing untrusted input

Related

Encoding — Base64, URL, HTML

Encode and decode text — Base64, URL percent-encoding, and HTML escaping — with the C#-faithful spellings…

Http.*

Make an outbound HTTP call to a URL you build at runtime — a webhook, a third-party API, a discovered endpoint…

Regex

Match, replace, split and CAPTURE with regular expressions — the C#-faithful System.Text.RegularExpressions spelling…