resgate is a free, open source api development & testing project written in Go and released under MIT. It has 739 GitHub stars, 69 forks and 16 open issues, and was last pushed 6 months ago. On this registry it ranks #158 of 186 tracked projects in API Development & Testing, with 5 head-to-head comparisons available.

What is resgate?

Resgate is an MIT-licensed, Go-based realtime API gateway for the RES protocol that sits in front of NATS-connected microservices and keeps REST, realtime, and RPC clients synchronized, built for teams shipping single page applications and realtime APIs on a microservices backend.

What it is

Resgate is a Go project implementing a realtime API gateway for the RES protocol, using NATS server as its messaging system. It is a server that handles every API request from clients instead of exposing microservices directly. Clients connect to Resgate over HTTP or WebSocket; Resgate forwards those requests to microservices across NATS, keeps track of which resource each client has requested, and maintains its own cache of resource data. When the microservice responsible for a resource sends an event, Resgate uses that event to update its cache and push the change to every subscribing client.

The concrete problem it solves is the fan-out of realtime state. Without a gateway, each client would need to reach each service directly and reimplement its own subscription and cache-invalidation logic, and every service would need to know which clients care about which resources. Resgate replaces that direct exposure of microservices by becoming the single endpoint that clients talk to, so services publish events and stay unaware of client connections. It lives in the NATS ecosystem and is aimed at new REST APIs that need realtime behavior, and at single page applications built with reactive frameworks such as React, Vue.js, or Modapp.

Key capabilities

  • Proxies client requests over HTTP and WebSocket to services on NATS, with configurable endpoints via -w, --wspath (default /) and -a, --apipath (default /api/).
  • Maintains a server-side cache per resource and pushes updates to subscribing clients whenever a responsible service emits an event.
  • Implements the RES protocol, documented as docs/res-protocol.md, docs/res-service-protocol.md, and docs/res-client-protocol.md for services and client libraries.
  • Exposes an OpenMetrics endpoint when started with -m, --metricsport, disabled by default with value 0.
  • Supports header authentication through -u, --headauth for resource methods and -t, --wsheadauth for WebSocket header authentication.
  • Controls NATS request timeouts with -r, --reqtimeout (default 3000 seconds) and the NATS target with -n, --nats.
  • Ships runnable examples including hello-world, edit-text, book-collection, jwt-authentication, password-authentication, and client-session, each with both service and client.

Who uses it and how

  • Teams building new REST APIs that need realtime functionality, where Resgate fronts the API and services publish change events rather than managing client connections.
  • Single page application developers using reactive frameworks such as React, Vue.js, or Modapp, who need client state to stay synchronized across concurrent edits — the edit-text and book-collection examples show multiple clients editing the same resource.
  • Microservices architectures where Node.js and Java services are kept off the public network and reached only through NATS.
  • Applications requiring authenticated realtime sessions, using the JWT and password authentication examples, and client sessions that survive reloads and reconnects.
  • Non-JavaScript backends: Go services use the go-res package, and .NET Core services use the RES Service for .NET package, while the in-repo examples are written in JavaScript for Node.js without additional libraries.

Getting started

The README's quickstart runs both containers with Docker, creating a shared network and launching nats plus the resgateio/resgate image with --nats nats://nats:4222. Both images are small, about 10 MB each, and other installation methods are listed at Resgate.io under Installation.

How it compares

This registry lists no comparable paid products that Resgate replaces, and the provided facts name no other realtime API gateways or competing projects, so it stands alone here. The related projects named in the README, go-res and RES Service for .NET, are service-side libraries for other languages rather than alternatives to the gateway itself.

When to use it — and when not to

A self-hoster must operate a NATS server alongside Resgate and wire them together on a shared network, plus decide on ports for HTTP, WebSocket, and optionally OpenMetrics; nothing beyond that is stated. Anyone unwilling to run NATS, or expecting a single self-contained binary with no messaging dependency, should not pick it, since NATS is the messaging system the gateway is built around. The README also notes its in-repo examples are JavaScript for Node.js only, so Go and .NET users must follow documentation outside this repository, and the topic list gives no indication of a managed hosted alternative.

project readme (upstream, from github) — read inline

Realtime API Gateway
Synchronize Your Clients

license Report Card Build Status Coverage

Visit Resgate.io for guides, live demos, and resources.


Resgate is a Go project implementing a realtime API gateway for the RES protocol with NATS server as messaging system.

It is a simple server that lets you create REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.

Used for building new REST APIs with real-time functionality, or when creating single page applications using reactive frameworks such as React, Vue.js, or Modapp.

Book Collection Animation
Screen capture from the Book Collection Example. Try out the Live demo version yourself.

How it works

Resgate handles all API requests from your clients, instead of directly exposing your micro-services (represented by Node.js and Java below). Clients will connect to Resgate, using either HTTP or WebSocket, to make requests. These requests are sent to the micro-services over NATS server, and Resgate will keep track on which resource each client has requested.

Whenever there is a change to the data, the responsible micro-service sends an event. Resgate will use this event to both update its own cache, and make sure each subscribing client is kept up-to-date.

Quickstart

If you install Docker, it is easy to run both NATS server and Resgate as containers:

docker network create res
docker run -d --name nats -p 4222:4222 --net res nats
docker run --name resgate -p 8080:8080 --net res resgateio/resgate --nats nats://nats:4222

Both images are small, about 10 MB each.

See Resgate.io - Installation for other ways of installation.

Examples

While Resgate may be used with any language, the examples in this repository are written in Javascript for Node.js, without using any additional library.

Example Description
Hello World Simple service serving a static message.
Edit Text Text field that can be edited by multiple clients concurrently.
Book Collection List of book titles & authors that can be edited by many.
JWT Authentication Showing how JWT tokens can be used for authentication.
Password Authentication Showing authentication with user and password credentials.
Client Session Creating client sessions that survive reloads and reconnects.

Note

All examples are complete with both service and client.

Protocol Specification

For more in depth information on the protocol:

Usage

resgate [options]

Server options

Option Description Default value
-n, --nats <url> NATS Server URL nats://127.0.0.1:4222
-i, --addr <host> Bind to HOST address 0.0.0.0
-p, --port <port> HTTP port for client connections 8080
-w, --wspath <path> WebSocket path for clients /
-a, --apipath <path> Web resource path for clients /api/
-r, --reqtimeout <seconds> Timeout duration for NATS requests 3000
-u, --headauth <method> Resource method for header authentication
-t, --wsheadauth <method> Resource method for WebSocket header authentication
-m, --metricsport <port> HTTP port for OpenMetrics connections 0 (disabled)
    --apiencoding <type> Encoding for web resources: json, jsonflat json
    --putmethod <methodName> Call method name mapped to HTTP PUT requests
    --deletemethod <methodName> Call method name mapped to HTTP DELETE requests
    --patchmethod <methodName> Call method name mapped to HTTP PATCH requests
    --wscompression Enable WebSocket per message compression
    --resetthrottle <limit> Limit on parallel requests sent on a system reset 0 (no limit)
    --referencethrottle <limit> Limit on parallel requests sent following references 0 (no limit)
-c, --config <file> Configuration file in JSON format

Security options

Option Description Default value
    --tls Enable TLS for HTTP false
    --tlscert <file> HTTP server certificate file
    --tlskey <file> Private key for HTTP server certificate
    --creds <file> NATS User Credentials file
    --natscert <file> NATS Client certificate file
    --natskey <file> NATS Client certificate key file
    --natsrootca <file> NATS Root CA file(s)
    --alloworigin <origin> Allowed origin(s): *, or ://\[:\] *

Logging options

Option Description
-D, --debug Enable debugging output
-V, --trace Enable trace logging
-DV Debug and trace

Common options

Option Description
-h, --help Show usage message
-v, --version Show version

Configuration

Configuration is a JSON encoded file. If no config file is found at the given path, a new file will be created with default values as follows.

Properties

{
    // URL to the NATS server.
    "natsUrl": "nats://127.0.0.1:4222",

    // Bind to HOST IPv4 or IPv6 address.
    // Empty string ("") means all IPv4 and IPv6 addresses.
    // Invalid or missing IP address defaults to 0.0.0.0.
    "addr": "0.0.0.0",

    // Port for the http server to listen on.
    // If the port value is missing or 0, standard http(s) port is used.
    "port": 8080,

    // Metrics port for the OpenMetrics http server to listen on.
    // If the port value is missing or 0, metrics are disabled.
    // Must be different from the configured api port.
    // Metrics are available at the path: /metrics
    "metricsPort": 0,

    // Path for accessing the RES API WebSocket.
    "wsPath": "/",

    // Path prefix for accessing web resources.
    "apiPath": "/api",

    // Timeout in milliseconds for NATS requests.
    "requestTimeout": 3000,

    // Size of message buffer for incoming NATS requests.
    "bufferSize": 8192,

    // Header authentication resource method for web resources.
    // Prior to accessing the resource, this resource method will be called,
    // allowing a service to set a token using information such as the request
    // headers.
    // Missing value or null will disable header authentication.
    // Eg. "authService.headerLogin"
    "headerAuth": null,

    // Header authentication resource method for WebSocket connections.
    // Prior to responding to a WebSocket connection, this resource method will
    // be called, allowing a service to set a token using information such as
    // the request headers.
    // Missing value or null will disable WebSocket header authentication.
    // Eg. "authService.headerLogin"
    "wsHeaderAuth": null,

    // Encoding for web resources.
    // Available encodings are:
    // * json - JSON encoding with resource reference meta data.
    // * jsonflat - JSON encoding without resource reference meta data.
    "apiEncoding": "json",

    // Call method name to map HTTP PUT method requests to.
    // Eg. "put"
    "putMethod": null,

    // Call method name to map HTTP DELETE method requests to.
    // Eg. "delete"
    "deleteMethod": null,

    // Call method name to map HTTP PATCH method requests to.
    // Eg. "patch"
    "patchMethod": null,

    // Flag enabling WebSocket per message compression (RFC 7692).
    "wsCompression": false,

    // Throttle on how many requests are sent in response to a system reset.
    // Once that the number of requests are sent, the server will await
    // responses before sending more requests. Zero (0) means no throttling.
    // Eg. 32
    "resetThrottle": 0,

    // Throttle on how many requests are sent when recursively following
    // resource references for a subscription.
    // Once that the number of requests are sent, the server will await
    // responses before sending more requests. Zero (0) means no throttling.
    // Eg. 32
    "referenceThrottle": 0,

    // Flag enabling tls encryption.
    "tls": false,

    // Certificate file path for tls encryption.
    "tlsCert": "",

    // Key file path for tls encryption.
    "tlsKey": "",

    // NATS User Credentials file.
    // Eg. "ngs.creds"
    "natsCreds": "",

    // NATS Client certificate file.
    // Eg. "client-cert.pem"
    "natsCert": "",

    // NATS Client certificate key file.
    // Eg. "client-key.pem"
    "natsKey": "",

    // NATS Root CA files.
    // Eg. ["rootCA.pem"]
    "natsRootCAs": [],

    // Allowed origin for CORS requests, or * to allow all origins.
    // Multiple origins are separated by semicolon.
    // Eg. "https://example.com;https://api.example.com"
    "allowOrigin": "*",

    // Flag enabling debug logging.
    "debug": false,

    // Flag enabling trace logging.
    "trace": false
}

Running Resgate

By design, Resgate will exit if it fails to connect to the NATS server, or if it loses the connection. This is to allow clients to try to reconnect to another Resgate instance and resume from there, and to give Resgate a fresh new start if something went wrong.

A simple bash script can keep it running:

#!/bin/bash
until ./resgate; do
    echo "Resgate exited with code $?.  Restarting.." >&2
    sleep 2
done

Documentation

Visit Resgate.io for documentation and resources.

It has guides on installation, configuration, writing services, scaling, queries, and other useful things. It also contains guides for ResClient when working with frameworks such as React, Vue.js, and Modapp.

Support Resgate

Resgate is an MIT-licensed open source project where development is made possible through community support.

If you'd like help out, please consider:

Contribution

Any feedback on the protocol and its implementation is highly appreciated!

If you find any issues with the protocol or the gateway, feel free to report them.

If you have created a service library, a client library, or some other tool or utility, please contact me to have it added to the list of resources.

Frequently asked questions

Is resgate free to use?

resgate is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does resgate do?

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.

What is resgate written in?

resgate is primarily written in Go. Its source is publicly available at https://github.com/resgateio/resgate, and it has 739 GitHub stars.