Brr.UriURIs and URI parameters.
Uri.t values are URL objects but we tweak the API to use RFC 3986 terminology and in contrast to the URL API we return component data without including separators like ':', '?' and '#' in the results.
The type for URL objects.
v ?base s is a URI from s relative to base (if specified). Raises in in case of error, use of_jstr if you need to deal with user input.
scheme u is the scheme of u. This is what the URL API calls the protocol but without including the trailing ':'.
host u is the host of u. This is not percent-decoded and what the URL API calls the hostname.
path u is the path of u. This is not percent-decoded and what the URL API calls pathname. Use path_segments for decoding the path.
Note. In hierarchical URI schemes like http this is "/" even if there is no path in u: no distinction is made between http://example.org and http://example.org/.
query u is the query of u. This not percent-decoded and what the URL API calls the search but without including the leading '?'. Use query_params to decode key-value parameters.
fragment u is fragment of u. This is not percent-decoded and what the URL API calls the hash but without including the leading '#'. Use fragment_params to decode key-value parameters.
val with_uri :
?scheme:Jstr.t ->
?host:Jstr.t ->
?port:int option ->
?path:Jstr.t ->
?query:Jstr.t ->
?fragment:Jstr.t ->
t ->
(t, Jv.Error.t) Stdlib.resultwith_uri u is u with the specified components updated. The components are assumed to be appropriately percent-encoded. See also with_path_segments, with_query_params and with_fragment_params.
type path = Jstr.t listThe type for absolute URI paths represented as non-empty lists of percent-decoded path segments. The empty list denotes the absence of a path.
Path segments can be Jstr.empty. The root path / is represented by the list [Jstr.empty] and /a by [Jstr.v "a"].
Warning. You should never concatenate these segments with a directory separator to get a file path because path segments may contain stray, percent-decoded, directory separators.
val path_segments : t -> (path, Jv.Error.t) Stdlib.resultpath_segments u determines the segments of the path of u and percent-decodes them. This is the empty list if the path is empty. The root path is [Jstr.empty].
val with_path_segments : t -> path -> (t, Jv.Error.t) Stdlib.resultwith_path_segments u segs is u with a path made by percent-encoding the segments, prepending a '/' to each segment and concatenating the result.
Note. In hierarchical URI schemes like http an empty segs is mapped to the root path, see path.
module Params : sig ... endURI fragment or query parameters.
query_params u is Params.of_jstr (query u).
with_query_params u ps is u with a query defined by parameters ps.
fragment_params u is Params.of_jstr (fragment u).
with_fragment_params u ps is u with a fragment defined by parameters ps.
val of_jstr : ?base:Jstr.t -> Jstr.t -> (t, Jv.Error.t) Stdlib.resultof_jstr ~base s is a URL from s relative to base (if specified). Note that if s is relative and base is unspecified the function errors.
to_jstr u is u as a JavaScript string. The result is percent-encoded.
val encode : Jstr.t -> (Jstr.t, Jv.Error.t) Stdlib.resultencode s percent-encodes an UTF-8 representation of s. See encodeURI.
Warning. This encodes according to RFC2396 not according to RFC3986 which reserves a few more characters.
val decode : Jstr.t -> (Jstr.t, Jv.Error.t) Stdlib.resultdecode s percent-decodes a UTF-8 representation of s. See decodeURI.
val encode_component : Jstr.t -> (Jstr.t, Jv.Error.t) Stdlib.resultencode s percent-encodes a UTF-8 representation of s. See encodeURIComponent.
val decode_component : Jstr.t -> (Jstr.t, Jv.Error.t) Stdlib.resultdecode s percent-descodes a UTF-8 representation of s. See decodeURIComponent. Note that this has the same effect as decode.