ReScript WebAPI
ReScript bindings for everything you need in the browser.
Installation
Section titled “Installation”ReScript 13.0.0-alpha.7 is the compiler baseline, and library alpha releases may
include breaking changes. See project status for the accepted peer range
and its testing limits.
Install the package and tested compiler:
npm install @rescript/webapi@alpha && npm install --save-dev rescript@13.0.0-alpha.7bun i @rescript/webapi@alpha && bun add --dev rescript@13.0.0-alpha.7The @alpha install command targets the published alpha dist-tag. The planned 1.0.0-alpha.1
candidate is not published yet; see project status for the current tag and
note that candidate installation is verified from its packed tarball.
Add the source directory and package dependency to rescript.json:
{ "name": "webapi-consumer", "sources": [{ "dir": "src" }], "dependencies": ["@rescript/webapi"]}After installing the package , you can use bindings for the various Web APIs as defined in MDN.
let location = WebAPI.DOM.window->WebAPI.Window.location
// Access properties using `.`let href = location.href
// Invoke methods using the `->TypeModule.method`location->WebAPI.Location.reloadlet location = window.location;
let href = location.href;
location.reload();
export { location, href,}Save the ReScript sample in src/Main.res, then compile it with npx rescript build.