Skip to content
프로젝트

소개

Connect의 TypeScript 구현입니다. 제대로 작동하는 Protobuf RPC입니다.

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
+1
in 7 days
+2
in 15 days
+8
in 1 month
+13

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Connect for ECMAScript

License Build NPM Version

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

A small example

With Connect, we define our schema first:

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

And with the magic of code generation, we can implement and serve our service:

import * as http from "node:http";
import type { ConnectRouter } from "@connectrpc/connect";
import { connectNodeAdapter } from "@connectrpc/connect-node";
import { createValidateInterceptor } from "@connectrpc/validate";
import type { SayRequest } from "./gen/eliza_pb";
import { ElizaService } from "./gen/eliza_pb";

// The adapter turns our RPC routes into a Node.js request handler.
const handler = connectNodeAdapter({
  // Validation via Protovalidate is almost always recommended
  interceptors: [createValidateInterceptor()],
  routes: (router: ConnectRouter) => {
    router.service(ElizaService, {
      say(req: SayRequest) {
        return {
          sentence: `You said "${req.sentence}"`,
        };
      },
    });
  },
});

http.createServer(handler).listen(8080);

Calling an RPC is just as simple. You create a client with your server's URL and call a method:

import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_pb";

const client = createClient(
  ElizaService,
  createConnectTransport({
    httpVersion: "1.1",
    baseUrl: "http://localhost:8080",
  }),
);

try {
  const res = await client.say({ sentence: "Hello, world!" });
  console.log(res.sentence);
} catch (err) {
  console.error(err);
}

Of course, a plain HTTP server isn't fit for production use! See Connect's server plugins for a guide to production deployment with Fastify, Next.js, Express, and more.

Simple, cURL-friendly RPC protocol

Unlike REST, the Remote Procedure Calls are type-safe, 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

Connect uses Protobuf-ES, the only fully-compliant Protobuf JavaScript library.

Connect implements three RPC protocols: The widely available gRPC and gRPC-Web protocols, and Connect's own protocol, optimized for the web. This gives you unparalleled interoperability across many platforms and languages, with type safety end-to-end.

Get started on the web

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

For other frameworks, such as Svelte, Vue, Next.js and Angular, see our examples. For TanStack Query, see our expansion pack Connect-Query.

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 serve your Connect RPCs with vanilla Node.js, or use our server plugins for Fastify, Next.js, and Express.

Migrating from version 1

If you are migrating from v1 to v2, check out our migration guide.

Other platforms

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!

Packages

Ecosystem

Compatibility

All maintained releases of Node.js (Current, Active LTS, and the Maintenance LTS release) are supported.

Baseline web browsers from the last 2.5 years are supported.

Same as Definitely Typed, we support versions of TypeScript that are less than 2 years old, with default compiler settings. Note that for some changes in TypeScript, it is impossible to support both new and old versions in the support window. We break the tie by supporting the newer version.

Status

This project is stable and follows semantic versioning, which means any breaking changes will result in a major version increase. Our goal is to not make breaking changes unless absolutely necessary.

Legal

Offered under the Apache 2 license.

관련 프로젝트 살펴보기

불러오는 중…