Go, WebAssembly, HTTP Requests and Promises

Go, WebAssembly, HTTP Requests and Promises

Go, WebAssembly, HTTP Requests and Promises. A guide to interacting with JavaScript from Go/Wasm

WebAssembly, or Wasm, is an open standard that allows developers to build apps that run inside a web browser using compiled programming languages. With WebAssembly, it’s possible to write components of web apps in languages such as C/C++, Rust, C#, and Go, among others, which run within the same sandbox as JavaScript. This allows things like porting existing libraries, leveraging capabilities not available in JavaScript, and running code faster because WebAssembly is compiled into a binary format.

Recently I’ve been experimenting with WebAssembly to be able to run some Go code in the browser. Specifically, I’ve been trying to port certain parts of  prvt, an open source project for storing end-to-end encrypted documents, to run within a web browser directly. The reason for the WebAssembly experiment was twofold: first, prvt makes extensive uses of cryptography and streams, both things which are not yet great in JavaScript; second, prvt itself is written in Go, so being able to reuse code in the browser would significantly simplify development.

For an introduction to using WebAssembly with Go, I recommend  this article on Golang Bot. Additionally, more information can be found in the Go project’s GitHub wiki and in the documentation for the  syscall/js package.

Note that as of writing, WebAssembly support in Go is still experimental. Because of that, the APIs might change too. This article was tested against Go 1.15.

This article contains four different yet connected things that I’ve learnt while working on the WebAssembly port and which I thought useful to share.

  1. Working with and creating JavaScript objects from Go code
  2. Creating Promises in Go for passing async results
  3. Making HTTP requests from Go code
  4. Streaming from Go code

web-development golang javascript webassembly

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Golang Web Development:Th Best Programming Language in 2020

Golang Web Development is the new trend globally. Get all the details about the Golang development here. Hire Golang Developers.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Hire Dedicated eCommerce Web Developers | Top eCommerce Web Designers

Build your eCommerce project by hiring our expert eCommerce Website developers. Our Dedicated Web Designers develop powerful & robust website in a short span of time.

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.