@bufbuild/connect

中文文档
0.13.0发布于 2023/08/18Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 25.1万

Type-safe APIs with Protobuf and TypeScript.

此软件包已被标记为弃用

Connect has moved to its own org @connectrpc and has a stable v1. Run `npx @connectrpc/connect-migrate@latest` to update. See https://github.com/connectrpc/connect-es/releases/tag/v0.13.1 for details.

原始使用文档

@bufbuild/connect

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.connectrpc.com/connectrpc.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.

Get started on the web

Follow our 10 minute tutorial where we use Vite and React to create a web interface for ELIZA.

React, Svelte, Vue, Next.js and Angular are supported (see examples), and we have an expansion pack for TanStack Query. We support all modern web browsers that implement the widely available fetch API and the Encoding API.

Get started on Node.js

Follow our 10 minute tutorial to spin up a service in Node.js, and call it from the web, and from a gRPC client in your terminal.

You can use vanilla Node.js, or our server plugins for Fastify or Express. We support the builtin http, and http2 modules on Node.js v16 and later.

版本与发布记录

@bufbuild/connect 共发布 14 个版本,首次发布于 2023/02/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.13.0latest2023/08/183 年前
0.12.02023/07/253 年前
0.11.02023/06/293 年前
0.10.12023/06/213 年前
0.10.02023/06/153 年前
0.9.12023/05/313 年前

关于 @bufbuild/connect 的常见问题

@bufbuild/connect 是什么?

Type-safe APIs with Protobuf and TypeScript.注意:该包已被作者标记为弃用——Connect has moved to its own org @connectrpc and has a stable v1. Run `npx @connectrpc/connect-migrate@latest` to update. See https://github.com/connectrpc/connect-es/releases/tag/v0.13.1 for details.

如何安装 @bufbuild/connect?

在项目目录运行 npm install @bufbuild/connect,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bufbuild/protobuf(^1.2.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bufbuild/connect 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bufbuild/connect 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bufbuild/connect 可以商用吗?

@bufbuild/connect 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bufbuild/connect 的下载量有多少?

根据 npm 官方下载统计,@bufbuild/connect 在 2026/10/09 – 2026/11/07 这 30 天内被下载 250,882 次,日均约 8,363 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bufbuild/connect 还在维护吗?

最新版本 0.13.0 发布于 2023/08/18(3 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/24。作者已将其标记为弃用,新项目建议寻找替代方案。