Low-level bindings to fetch for BuckleScript. bs-fetch
is intended as a thin layer atop the JS API, upon which more high-level and idiomatic libraries can be made. Once such a library has been established, these bindings will likely be refactored to be even thinner.
(* OCaml *)
let _ =
Js.Promise.(
fetch "/api/hellos/1"
|> then_ Response.text
|> then_ (fun text -> print_endline text |> resolve)
)
/* Reason */
Js.Promise.(
fetch "/api/hellos/1"
|> then_ Response.text
|> then_ (fun text => print_endline text |> resolve)
);
npm install --save bs-fetch
Then add bs-fetch
to bs-dependencies
in your bsconfig.json
:
{
...
"bs-dependencies": ["bs-fetch"]
}
See usage examples in examples/examples.ml
. The source is a single file!
- Rename
Bs_fetch
module toFetch
.Bs_fetch
is kept around as an alias for backwards compatibility, but should be considered deprecated.