Follow us on Facebook Follow us on Twitter Subscribe RSS Feed

Recent Comments

Professional Authors

Building A Web Application With Rust And Webassembly

Rust’s expressiveness and high level abstractions make it ideal for building intricate and complex user interfaces. Unfortunately, there is little consensus on what the best abstractions are. Ryan Carniato joins Jerod, Amelia, and Nick to discuss SolidjS – a declarative, efficient, and flexible JavaScript library for building user interfaces. At this time, I’m just designing my views and throwing around fake, hard-coded data until I have something that seems to work. I hung out here for about two days, until everything looked nice and all interactivity (button clicks, form submissions, etc.) got fleshed out.

rust for FrontEnd Development

This starts to matter when dealing with millions of keys which, as mentioned, is not uncommon with Workers KV. So, with the intro out of the way, let me tell you how I built Workers KV GUI, a cross-platform desktop application using Svelte, Redis, and Rust. In this post, I go into details about building a real production app with Hotwire and what we learnt as a team, plus some of the things we don’t like and the problems we bumped into. There’s lots of info out there about building a simple app with Turbo, but there’s very limited content about architecting apps, scaling or building anything that’s not simply a blog. This time we’re arguing whether or not single-page apps were a big mistake. This premise was inspired by Chris Ferdinandi’s SPAs were a mistake post.

Native Notifications

That’s the question Jonathan Creamer is here to answer. In so doing, we cover the past, present, and future of frontend tooling. You may prefer other Rust frameworks like MoonZoon or Yew. Heck, even Chris’s disclaimer of ‘when SPAs make sense’ section at the top is easily defeated by our Turbolinks implementation.

  • So now it’s Thursday and I still haven’t written any Redis code, but at least I know how to connect the two halves of my application’s brain together.
  • Webviewers are effectively browsers, which Tauri uses because they already exist on your system, and this means that our applications can remain pure web development products.
  • Not only did it save me a half-day-slog configuring my toolbelt, but the instant, HMR development server probably saved me a few hours of manually refreshing the browser — and then the Tauri viewer.
  • Basically the “…but it works on my machine” problem went away because all of the users were running the exact same localhost setup.
  • With an SPA, the entire site or app lives in a single HTML file.
  • Rust’s expressiveness and high level abstractions make it ideal for building intricate and complex user interfaces.
  • This is also to say that using Tauri was not a challenge — it was a massive relief.

There are some awesome Rust and WebAssembly projects out there. For example, Yew and Seed let you create front-end web apps with Rust in a way that feels almost like React.js. And, of course, SvelteKit certainly made this timeline possible. Not only did it save me a half-day-slog configuring my toolbelt, but the instant, HMR development server probably saved me a few hours of manually refreshing the browser — and then the Tauri viewer.

Next.js powers the biggest websites like Patreon, for use cases in e-commerce, travel, news, and marketing. Our platform enables frontend teams to do their best work. With performance and security at the center, Rust is the language for the next generation of apps. This is a lengthy, sprawling piece on the evolution of frontend development by someone who really gets the web. It also has its own art-direction and design so you’ll want to read it onsite vs in an Instapaper-alike.

Servers: Cool Once Again

Basically the “…but it works on my machine” problem went away because all of the users were running the exact same localhost setup. Through the Node.js layer, you could interact with the filesystem, run servers on multiple ports, or include a bunch of node_modules to — and I’m just spit-balling here — connect to a Redis instance. Luckily, there are a few alternatives — I evaluated Svelte NodeGui and Tauri. Both choices offered significant application size and utilization savings by relying on native renderers the operating system offers, instead of embedding a copy of Chrome to do the same work. NodeGui does this by relying on Qt, which is another Desktop/GUI application framework that compiles to native views.

Instead of including a Node.js runtime, Tauri applications are built with Rust, a low-level systems language. This is how Tauri itself interacts with the operating system and “borrows” its native webviewer. All of the Tauri toolkit is compiled , which allows the built application to remain small and efficient.

I’m tempted to call this the “easy part” but, given that you can use any and all HTML, CSS, and JavaScript frameworks, libraries, or patterns, choice paralysis can easily set in… which might be familiar, too. If you have a favorite front-end stack, great, use that! For this application, I chose to use Svelte because, for me, it certainly makes and keeps things easy. To build our components, we use the yew, crate which is, as I’m writing this, the most advanced and supported Rust frontend framework. Rust does not have a dominant framework at the level of Django or Rails. Most Rust frameworks are smaller and modular, similar to Flask or Sinatra.

However, this also means that we, the application developers, can include any additional crates — the “npm module” equivalent — into the built application. And, of course, there’s an aptly named redis crate that, as a Redis client driver, allows the Workers KV GUI to connect to any Redis instance. Also, as web developers, we expect to bring https://wizardsdev.com/ all our tooling with us. Again, this phase of the project is no different than your typical web application development cycle. You can expect to run yarn dev as your main command and feel at home. Keeping with an “easy” theme, I’ve elected to use SvelteKit, which is Svelte’s official framework and toolkit for building applications.

You Don’t Need A Ui Framework

Optimizing for cost and network load, we decided that a key’s value should only be fetched on command. This introduces a REFRESH button that, when clicked, interacts with the REST API once again, then dispatches a command so that the Redis client can update that key individually. Saving all the data into some kind of in-browser storage is totally viable, but it saves it locally to your machine. This means that if you have team members trying to do the same thing, everyone will have to fetch and save all the data on their own machines, too. Ideally, this Workers KV application should have the option to connect to and sync with an external database. That way, when working in team settings, everyone can tune into the same data cache to save time — and a couple bucks.

rust for FrontEnd Development

This means less time writing boilerplate and less time installing dependencies. Compile the code to WebAssembly, prepare JS/TS frontend and finish the course by creating the practical Snake game that can run in any browser. Very well written and very informative article, thanks Buttons or Dropdowns in FrontEnd Development for that! Especially for seasoned JS but novice Rust developer . This is also to say that using Tauri was not a challenge — it was a massive relief. I definitely plan to use Tauri again in the future, especially knowing that I can use just the webviewer if I want to.

It’s Time For A Data

The SvelteKit CLI is accessed through the svelte-kit binary name. Writing yarn svelte-kit build, for example, tells yarn to fetch its local svelte-kit binary, which was installed via a devDependency, and then tells SvelteKit to run its build command. This guide is being tentatively hosted atschell.github.io/intro-to-rust-web-dev.

Pages are assemblages of components and are components themselves in yew. And finally, Services are auxiliary utilities to wrap low-level features or external services such as an HTTP client, Storage… For example, the Login page matches the /login route. Every Git branch and PR receives a live, production-like URL that everyone on your team can visit.

Connecting The Dots In Public

After the initial load, everything about the app is handled with JavaScript. This is, in theory, supposed to result in web apps that feel as fast and snappy as native apps. People looking for the practical Rust/WebAssembly/TS development guide. Function, which is effectively console.log for Rust, that the greet command used. It appears in the terminal’s console window — not the browser console — because this code still runs on the Rust/system side of things. The Tauri application compiles and is aware of the fact that it owns a “greet” command.

Checking If The Site Connection Is Secure

But I digress… read this post it’s a good one for sure. My app is basically a browser tab running Svelte, right? Having thought about it for a bit, I decided to use Redis as my backing store because it also is a key-value store.

At Cloudflare, we have a great product called Workers KV which is a key-value storage layer that replicates globally. It can handle millions of keys, each of which is accessible from within a Worker script at exceptionally low latencies, no matter where in the world a request is received. Workers KV is amazing — and so is its pricing, which includes a generous free tier. Then we declare all the possible routes of our application. A hard and fast introduction to Rust-to-WASM compilation and using web-sys to write Rust that runs in the browser. For more information about Rust and WebAssembly, check out the Rust and WebAssembly Book.

By using the OS’s native web renderer, the size of a Tauri app can be less than 600KB. Relicensing and redistribution is possible thanks to MIT or MIT/Apache 2.0 licensing where applicable. Hyperapp claims to be twice as fast as React, weighs in at 1.8KB, and renders interactively in ~10ms.

The Vercel platform makes it a collaborative experience with deploy previews for every code change, by seamlessly integrating with GitHub, GitLab, and Bitbucket. Build an optimized, secure, and frontend-independent application for multi-platform deployment. Like any critique, it begs for a prescription and I didn’t give one, other than gesturing toward server-side frameworks like Rails and Django. I had queued up some time to really dive into the frameworks, but things like walking in parks have taken priority, so here’s just a grand tour. Today, GraphQL is being used by several production apps across PayPal. It is now a default pattern to use GraphQL for building new UI apps.

You will likely have to roll your own components such as date pickers. I find it relatively hard to get started with Tauri – even though it’s extensive documentation – that interests itself with a “transpiled” framework. Now I know with Vite I can develop my front-end whichever framework as my heart please and then add Tauri to it. Components are reusable pieces of functionality or design.

In: Uncategorized Posted By: Date: Nov 24, 2021
Leave comment commentinfo No comment & 0 views

Leave Comments

Name*

Email*
Website
Email me whenever there is new comment