Connect-Web

Type-safe APIs with Protobuf and TypeScript.

README


Connect for ECMAScript


License NPM Version NPM Version NPM Version

Connect is a family of libraries for building and consuming APIs on
different languages and platforms.

With Connect, you define your schema first:

  1. ```
  2. service ElizaService {
  3.   rpc Say(SayRequest) returns (SayResponse) {}
  4. }
  5. ```

And with the magic of code generation, this schema produces servers and clients:

  1. ```ts
  2. const answer = await eliza.say({sentence: "I feel happy."});
  3. console.log(answer);
  4. // {sentence: 'When you feel happy, what do you do?'}
  5. ```

Unlike REST, the RPCs you use with Connect are typesafe end to end, but they are
regular HTTP under the hood. You can see all requests in the network inspector,
and you can curl them if you want:

  1. ```shell
  2. curl \
  3.     --header 'Content-Type: application/json' \
  4.     --data '{"sentence": "I feel happy."}' \
  5.     https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say
  6. ```

With Connect for ECMAScript, you can spin up a service in Node.js and call it
from the web, the terminal, or native mobile clients. Under the hood, it uses
Protocol Buffers for the schema, and
implements RPC (remote procedure calls) with three protocols: The widely available
gRPC and gRPC-web, and Connect's own protocol,
optimized for the web. This gives you unparalleled interoperability with
full-stack type-safety.

To get started, head over to the docs
for a tutorial. You will also find API documentation and best practices there.
For using Connect with your favorite frontend framework, take a look at

Ecosystem


  Examples for using Connect with various TypeScript web frameworks and tooling
  TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers
  Idiomatic gRPC & Connect RPCs for Swift.
  Go implementation of gRPC, gRPC-Web, and Connect
  demonstration service powering demo.connect.build
Buf Studio: web UI for ad-hoc RPCs
  gRPC-Web and Connect interoperability tests


Packages


  Implements browser clients for the Connect and gRPC-web protocols (source code).
  Implements Node.js clients and servers for the Connect, gRPC-web, and gRPC protocols (source code).
  Code generator plugin for the services in your schema (source code).


Supported Platforms


We support all modern web browsers that implement the widely available
and the Encoding API.
The libraries and the generated code are compatible with ES2017 and TypeScript 4.1.

On Node.js, we use the http, https, or http2 modules, and support v16, v17 and v18.

Would you like to use Connect on other platforms like Bun, Deno, Vercel’s Edge Runtime,
or Cloudflare Workers? We’d love to learn about your use cases and what you’d like to do
with Connect. You can reach us either through the Buf Slack
or by filing a GitHub issue and we’d
be more than happy to chat!


Status


This project is a beta: we rely on it in production, but we may make a few
changes as we gather feedback from early adopters. Join us on Slack
or see the roadmap discussion for details.


Legal


Offered under the Apache 2 license.