Skip to content

Latest commit

 

History

History
106 lines (78 loc) · 4.93 KB

README.md

File metadata and controls

106 lines (78 loc) · 4.93 KB

Connect for ECMAScript

License NPM Version NPM Version

Connect is a family of libraries for building type-safe APIs with different languages and platforms.
@bufbuild/connect brings them to TypeScript, the web browser, and to Node.js.

With Connect, you define your schema first:

service ElizaService {
  rpc Say(SayRequest) returns (SayResponse) {}
}

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

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

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:

curl \
    --header 'Content-Type: application/json' \
    --data '{"sentence": "I feel happy."}' \
    https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say

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 connect-es-integration.

Packages

Supported Platforms

  • We support all modern web browsers that implement the widely available fetch API and the Encoding API.
    React, Svelte, Vue, Next.js and Angular are supported, and an expansion pack for TanStack Query.
  • On Node.js, we use the http, https, or http2 modules, and support v16, v17 and v18.
    You can spin up a vanilla Node.js servers, or use our plugin for Fastify, or for Express.
  • The libraries and the generated code are compatible with ES2017 and TypeScript 4.1.

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!

Ecosystem

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.