package brr

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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

type t

The type for URL objects.

val 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.

val scheme : t -> Jstr.t

scheme u is the scheme of u.

val host : t -> Jstr.t

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

val port : t -> int option

port u is the port of u.

val path : t -> Jstr.t

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

val query : t -> Jstr.t

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

val fragment : t -> Jstr.t

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

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.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

module Params : sig ... end

URI fragment or query parameters.

URI Encoding

val encode : Jstr.t -> (Jstr.t, Jv.Error.t) Stdlib.result

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

val decode : Jstr.t -> (Jstr.t, Jv.Error.t) Stdlib.result

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

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

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

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

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

Converting

val of_jstr : ?base:Jstr.t -> Jstr.t -> (t, Jv.Error.t) Stdlib.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.

val to_jstr : t -> Jstr.t

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

OCaml

Innovation. Community. Security.