Vanilla HTML + JS
A single self-contained HTML file that lists devices using the SDK. Save as index.html, host anywhere, open in a browser. No build, no install.
Full example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My devices</title>
</head>
<body>
<h1>My devices</h1>
<ul id="devices"><li>Loading…</li></ul>
<script type="module">
import { Sensrik } from 'https://docs.sensrik.com/sensrik.js';
// 1. Authenticate. Two ways — pick one.
//
// (a) Drop-in API key (best for trusted frontends + scripts):
const sensrik = new Sensrik({ apiKey: 'sk_REPLACE_ME' });
//
// (b) End-user email + password (best for customer logins):
// const sensrik = new Sensrik();
// await sensrik.auth.login('user@example.com', 'their-password');
// 2. Use it.
try {
const devices = await sensrik.devices.list();
document.getElementById('devices').innerHTML = devices.length === 0
? '<li>No devices yet.</li>'
: devices.map(d => `<li>${d.name} — ${d.isOnline ? '🟢 online' : '⚪ offline'}</li>`).join('');
} catch (err) {
document.getElementById('devices').innerHTML = `<li style="color:red">Failed: ${err.message}</li>`;
}
</script>
</body>
</html>
Why this works without a build step
- The SDK is served as an ES module from
https://docs.sensrik.com/sensrik.js. - Modern browsers (last 3 years) support
<script type="module">+ top-levelawaitnatively. - No bundler, no transpiler, no
node_modules. Saves bytes, ships faster.
Want the full storefront?
For login + device list + device detail with live readings, ask your Sensrik admin for the storefront template. Same shape as this snippet, more pages.