DEV Community

loading...
Cover image for Emulate a Go HTTP server in your browser

Emulate a Go HTTP server in your browser

nlepage profile image Nicolas Lepage ・1 min read

Hi 👋 I'd like to share github.com/nlepage/go-wasm-http-server

GitHub logo nlepage / go-wasm-http-server

WebAssembly Go HTTP Server embedded in a ServiceWorker

Welcome to go-wasm-http-server 👋

Go Reference License: Apache 2.0 Twitter: njblepage

Build your Go HTTP Server to WebAssembly and embed it in a ServiceWorker!

Examples

How?

Talk given at the Go devroom of FOSDEM 2021 explaining how go-wasm-http-server works:

Deploy a Go HTTP server in your browser Youtube link

The slides are available here.

Why?

go-wasm-http-server can help you put up a demonstration for a project without actually running a Go HTTP server.

Requirements

go-wasm-http-server requires you to build your Go application to WebAssembly, so you need to make sure your code is compatible:

  • no C bindings
  • no System dependencies such as file system or network (database server for example)

Usage

Step 1: Build to js/wasm

In your Go code, replace http.ListenAndServe() (or net.Listen() + http.Serve())…




This project allows you to build Go HTTP handlers to WebAssembly and embed it in a ServiceWorker to emulate an HTTP server!

I'd really appreciate to have feedback from people who would give it a try 🙂

The readme has a usage section and some examples to guide you.

Here is a video from FOSDEM 21 explaining how this works:

Contributions on the project are more than welcome.

Thanks!

Discussion (0)

pic
Editor guide