package prr

  1. Overview
  2. Docs

Module Brr.UriSource

URIs and URI parameters.

Uri.t values are URL objects but we tweak the API to return data according to RFC 3986 terminology: we don't return separators like ':', '?' and '#' in the data and we use host for what is hostname in the URL API. Also the data we return is URL (percent) decoded).

URIs

Sourcetype t

The type for URL objects.

Sourceval v : ?base:Jstr.t -> Jstr.t -> t

v ?base s is an 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.

Sourceval scheme : t -> Jstr.t

scheme u is the scheme of u.

Sourceval host : t -> Jstr.t

host u is the host of u. Warning this is what the URL API calls hostname.

Sourceval port : t -> int option

port u is the port of u.

Sourceval path : t -> Jstr.t

path u is the path of u. Note that this "/" if there is no path.

Sourceval query : t -> Jstr.t

query u is the query of u (without the leading '?').

Sourceval fragment : t -> Jstr.t

fragment u is fragment of u (withouth the leading '#').

Sourceval 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) result

with_uri u is u with the specified components updated. The given parameters are URL (percent) encoded by the function.

Fragment or query parameters

Sourcemodule Params : sig ... end

URI fragment or query parameters.

URI Encoding

encode s URL encodes s by percent-encoding an UTF-8 representation of s. See encodeURI.

decode s URL decodes s by percent-decoding an UTF-8 representation of s. See decodeURI.

Sourceval encode_component : Jstr.t -> (Jstr.t, Jv.Error.t) result

encode s URL encodes s by percent-encoding an UTF-8 representation of s. See encodeURIComponent.

Sourceval decode_component : Jstr.t -> (Jstr.t, Jv.Error.t) result

decode s URL decodes s by precent-decoding an UTF-8 representation of s. See decodeURIComponent.

Converting

Sourceval of_jstr : ?base:Jstr.t -> Jstr.t -> (t, Jv.Error.t) result

of_jstr ~base s is an URL from s relative to base (if specified). Note that if s is relative and base is unspecified the function errors.

Sourceval to_jstr : t -> Jstr.t

to_jstr u is u as a JavaScript string. The result is URL encoded.

OCaml

Innovation. Community. Security.