On this page:
URL
URL.scheme
URL.user
URL.host
URL.port
URL.is_  path_  absolute
URL.path
URL.query
URL.fragment
Path  With  Params
Path  With  Params.path
Path  With  Params.params
Key  Value
Key  Value.key
Key  Value.value
URL.from_  string
URL.from_  path
relative_  path_  to_  relative_  url_  string
URL.to_  string
URL.to_  path
URL.add
current_  encode_  mode
Encode  Mode
Encode  Mode.recommended
Encode  Mode.unreserved
URL.from_  handle
URL.to_  handle

1 URL Parsing🔗ℹ

class

class URL(

  ~scheme: scheme :: maybe(String) = #false,

  ~user: user :: maybe(String) = #false,

  ~host: host :: maybe(String) = #false,

  ~port: port :: maybe(NonnegInt) = #false,

  ~is_path_absolute: is_path_absolute :: Boolean = #false,

  ~path: path :: List.of(PathWithParams) = [],

  ~query: query :: List.of(KeyValue) = [],

  ~fragment: fragment :: maybe(String) = #false

)

 

class

class PathWithParams(

  path :: String || Path.Dot,

  params :: List.of(String)

)

 

class

class KeyValue(

  key :: Symbol,

  value :: maybe(String)

)

A class to represent URLs as defined by RFC 3986. The following diagram illustrates the parts:

  http://sky@www:801/cgi-bin/finger;xyz?name=shriram;host=nw#top

  {1-}   {2} {3} {4}{---5---------} {6} {----7-------------} {8}

  

  1 = scheme, 2 = user, 3 = host, 4 = port,

  5 = path (two elements),  6 = param (of second path element),

  7 = query, 8 = fragment

The strings inside the user, path, query, and fragment fields are represented without URL-syntax-specific quoting. The URL.from_string function and URL.to_string method translate encodings, such as converting a %20 into a space and back again.

By default, query associations are parsed with either ; or & as a separator, and they are generated with & as a separator. The form.current_separator_mode parameter adjusts the behavior.

An empty string at the end of the path list corresponds to a URL that ends in a slash. For example, the result of URL.from_string("http://rhombus-lang.org/a/") has a path field with strings "a" and "", while the result of URL.from_string("http://rhombus-lang.org/a") (string->url "http://racket-lang.org/a") has a path field with only the string "a".

When a "file" URL is represented by a URL instance, the path field is mostly a list of path elements. For Unix paths, the root directory is not included in path; its presence or absence is implicit in the is_path_absolute flag. For Windows paths, the first element typically represents a drive, but a UNC path is represented by a first element that is "" and then successive elements complete the drive components that are separated by / or \.

The URL.from_string and URL.from_string functions convert from strings and paths to URLs.

The relative_path_to_relative_url_string converts a relative path into a string that represents a relative URL reference (e.g., using forward slashes, even on Windows).

Converts a URL to a string or path.

The URL.to_string conversion is used to print a URL object in #'text mode, while #'expr mode uses the default printing format for a class instance.

method

method (u :: URL).add(rel :: String) :: URL

Adds a relative URL rel to u to produce a new URL.

context parameter

Parameter.def current_encode_mode :: EncodeMode

 

enumeration

enum EncodeMode:

  recommended

  unreserved

The current_encode_mode parameter determines how queries are encoded.

function

fun URL.from_handle(handle :: Any) :: URL

 

method

method (u :: URL).to_handle() :: Any

Converts between URL objects and the URL representation used by Racket libraries.