Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

NATS <-> websocket gateway

A websocket gateway for NATS, usable as a backend for elm-nats and websocket-nats.


  • TLS support
  • Each NATS command is sent as a separate websocket message
  • Provides a hook to change the CONNECT phase, allowing the http server to handle the connection itself (for example based on a cookie of the http request)
  • Easily embeddable in a bigger http server
  • Supports both text (default) and binary (by adding '?mode=binary' to the url) messages

Basic usage

Fetch the source:

go get -u

Install and run the default binary

go install
nats-websocket-gw --no-origin-check

and/or integrate it in your http server:

package main

import (


func main() {
	gateway := gw.NewGateway(gw.Settings{
		NatsAddr: "localhost:4222",
	http.HandleFunc("/nats", gateway.Handler)
	http.ListenAndServe("", nil)

How does it differ from other nats-websocket servers ?

  • Rest to NATS Proxy provides a websocket based implementation. The approach is pretty different though, as the websockets do not transport the whole NATS protocol, but only the data of the messages (websockets are opened for each subscribed subject).

  • ws-tcp-relay, which the proposed backend for websocket-nats is a generic ws-tcp gateway. As such, it:

    • does not allow for TLS connections to NATS because the TLS negociation cannot be done immediately (the NATS protocol has a clear text 'INFO' exchange before TLS handshake)
    • send websocket messages that may contain several NATS commands.


A websocket to NATS gateway




No releases published


No packages published
You can’t perform that action at this time.