Fmlib_js.Http_requestHttp requests made in the browser.
This module uses the javascript object XMLHttpRequest to make http requests.
Type of a http request object
All properties of an http request object see.
val event_target : t -> Event_target.tView the request as an event target.
It is recommended to add a listener for the loadend event which is fired after completion (successful or unsuccessful) of the request.
The lister shall check the status property (200: Ok, 404: not found, ...). In case of success, the property responseText is a nullable string which contains the response.
Status codes see.
The following decoder can be used to decode the status and the response text of a terminated request:
Base.Decode.(
field "target"
(let* status = field "status" int in
let* response = field "responseText" (option string) in
return (status, response))
)val make_text : string -> string -> (string * string) list -> string -> tmake_text method url headers text
Make an http request with the string text as payload.
make_file method url headers file
Make an http request with contents of file as payload.
val ready_state : t -> intReady state of the request
0: request not initialized
1: open has been called
2: send has been called
3: loading
4: completeval status : t -> intThe status of the completed http request
E.g.: 200: Ok, 403: forbidden, 404: not found, ...
val response_text_value : t -> Base.Value.tThe response text of the completed http request as a javascript value.
val response_text_string : t -> stringThe response text of the completed http request as a string.