Member-only story
Making Web Apps in Rust: Part 3— Utilizing Web APIs
In this part, we are going to animate our clocks!

Articles in the Series:
- Making Web Apps in Rust: Part 1 — Introduction
- Making Web Apps in Rust: Part 2 — HTML & Styling
- Making Web Apps in Rust: Part 3 — Utilizing Web APIs
Brief Overview
Should you come from a JavaScript background, your initial thought might be, “Just employ useInterval, what could be simpler?” Yet, this is where the complexities arise if you’re considering Rust. Even after a few hours dabbling with Rust and mastering some rudimentary concepts, you’ll end up with code that’s compact and neat. But I can’t recall another language that can make handling such an ostensibly trivial matter so challenging. However, it’s worth noting that it does become much more manageable with experience.
Leveraging Web APIs
I want to stress that the aim of this article is to provide insight into what it’s like to develop purely Web Applications using Rust. Here’s my perspective on this:
- If your aim is to create a Web-first application, TypeScript is your best bet. If the need for high-performance operations arises, code those in Rust and export them as an npm package using wasm-pack.
- If your objective is to develop cross-platform applications, avoid using WEB APIs directly. Instead, opt for cross-platform abstractions.
In this installment, we’ll explore how to use the browser’s setInterval. This might seem more complex than expected, but it’ll afford us the opportunity to delve into three crucial aspects of Rust: ownership, closures, and usage of Web APIs. Let’s start with the least ‘rusty’ one — Web APIs.
Using Web APIs in Rust
Mostly, when Rust for the Web is discussed, it’s often associated with the wasm-bindgen tool — this facilitates high-level bindings between Rust and JavaScript. Here are some key features highlighted in the official documentation:
- Importing JS functionality into Rust such as DOM manipulation, console logging, or performance monitoring.
- Exporting Rust…