Module type Signatures.Fetch

The Cosmetyc library has ports both for native compilation and compilation to JavaScript. As such, core modules can't directly fetch a webpage as the underlying mechanism will be very different in both contexts. Instead, we thus provide this module signature, both implemented in Cosmetyc_native and Cosmetyc_js: any module needing to fetch resources from the Internet can base on such a module as a parameter.

module Promise : sig ... end

Fetching URL is not always done synchronously: they are usually embedded within a promise.

type error = {
  1. status : int;
  2. message : string;
}

An error message.

val fetch : ?using_method:string -> ?header:(string * string) list -> string -> (string, error) Stdlib.result Promise.t

Fetch a URL. Get in result either the content of the object, or an error message. The default using_method is GET, and the default header empty.