2.0.2 • Published 8 months ago

@connectrpc/connect-node v2.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

@connectrpc/connect-node

Connect is a family of libraries for building and consuming APIs on different languages and platforms, and @connectrpc/connect brings type-safe APIs with Protobuf to TypeScript.

@connectrpc/connect-node provides the following adapters for Node.js:

createConnectTransport()

Lets your clients running on Node.js talk to a server with the Connect protocol:

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

+ // A transport for clients using the Connect protocol with Node.js `http` module
+ const transport = createConnectTransport({
+   baseUrl: "https://demo.connectrpc.com",
+   httpVersion: "1.1"
+ });

const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence) // you said: I feel happy.

createGrpcTransport()

Lets your clients running on Node.js talk to a server with the gRPC protocol:

import { createClient } from "@connectrpc/connect";
+ import { createGrpcTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

+ // A transport for clients using the gRPC protocol with Node.js `http2` module
+ const transport = createGrpcTransport({
+   baseUrl: "https://demo.connectrpc.com",
+ });

const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence) // you said: I feel happy.

createGrpcWebTransport()

Lets your clients running on Node.js talk to a server with the gRPC-web protocol:

import { createClient } from "@connectrpc/connect";
+ import { createGrpcWebTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

+ // A transport for clients using the Connect protocol with Node.js `http` module
+ const transport = createGrpcWebTransport({
+   baseUrl: "https://demo.connectrpc.com",
+   httpVersion: "1.1"
+ });

const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence) // you said: I feel happy.

connectNodeAdapter()

Run your Connect RPCs on the Node.js http, https, or http2 modules.

// connect.ts
import { ConnectRouter } from "@connectrpc/connect";

export default function (router: ConnectRouter) {
  // implement rpc Say(SayRequest) returns (SayResponse)
  router.rpc(ElizaService, ElizaService.methods.say, async (req) => ({
    sentence: `you said: ${req.sentence}`,
  }));
}
// server.ts
import * as http2 from "http2";
+ import routes from "connect";
+ import { connectNodeAdapter } from "@connectrpc/connect-node";

http2.createServer(
+ connectNodeAdapter({ routes }) // responds with 404 for other requests
).listen(8080);

With that server running, you can make requests with any gRPC, gRPC-Web, or Connect client.

buf curl with the gRPC protocol:

buf curl --schema buf.build/connectrpc/eliza \
  --protocol grpc --http2-prior-knowledge \
  -d '{"sentence": "I feel happy."}' \
  http://localhost:8080/connectrpc.eliza.v1.ElizaService/Say

curl with the Connect protocol:

curl \
    --header "Content-Type: application/json" \
    --data '{"sentence": "I feel happy."}' \
     --http2-prior-knowledge \
    http://localhost:8080/connectrpc.eliza.v1.ElizaService/Say

Node.js with the gRPC protocol:

import { createClient } from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

const transport = createGrpcTransport({
  baseUrl: "http://localhost:8080",
});

const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence); // you said: I feel happy.

A client for the web browser actually looks identical to this example - it would simply use createConnectTransport from @connectrpc/connect-web instead.

Getting started

To get started with Connect, head over to the docs for a tutorial, or take a look at our example.

@everything-registry/sub-chunk-195@hackclub/inventorytcubesa-sdkwgcthirdwaveimpaction-ai@wolfcoded/nestjs-bufconnect@wundergraph/apollo-to-cosmo-metrics@thirdwavelabs/cli@thirdwavelabs/node@tinyburg/doorman@vect.io/change.connect.client.node@vect.io/api.connect.change.client.binding.node@versori/run@utxorpc/sdkalignai@zitadel/client@atproto/bsky@atproto/bsync@clioplaylists/clio@atls/files-rpc-client@hackclub/bag@harutakax/grpc-health-check@adrianfalleiro/vitess@bosca/common@bosca/protobufs@bosca/workflow-activities-api@bosca/workflow-worker-api@lage-run/rpc@kernelminds/scailo-sdk@saibdev/utxorpc-sdk@scalekit-sdk/node@riza-io/quickdb@riza-io/sandbox@rewards-system/reward-agents-rpc-client@rewards-system/reward-operations-rpc-client@rewards-system/reward-points-rpc-client@rewards-system/reward-programs-rpc-client@rewards-system/rewards-rpc-clientscanswift-sdkplanetscale-stream-tsreduction-tschow-utxo-sdkbrambltsfunction-sdk-typescript@stately-cloud/client@stigg/sidecar@spy.dev/agent-js@substreams/node@taubyte/spore-drivefhub@aurora-codestash/codestash@luxfi/utila@depot/sdk-node@jamm-pay/node-sdk@antinvestor/profile@antinvestor/property@antinvestor/settings@antinvestor/common@antinvestor/ledger@antinvestor/lostid@antinvestor/notification@antinvestor/ocr@antinvestor/partition@antinvestor/payment@arcjet/transport@inco/js@files-system/files-rpc-client@nillion/client-vms@normalframework/applications-sdk@futuristick/atproto-bsky@encore.dev/node-runtime@aserto/aserto-node@hiveops/apiary@hiveops/node@hyveos/server@iameli/bsky@iameli/bsync@hyperledger/cactus-cmd-api-server@olvid/bot-node@getstanza/hub-client-grpc@gitpod/public-api
2.0.0-rc.3

12 months ago

2.0.2

8 months ago

2.0.1

9 months ago

2.0.0

11 months ago

2.0.0-rc.2

12 months ago

2.0.0-rc.1

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

2.0.0-beta.2

1 year ago

1.5.0

1 year ago

2.0.0-beta.1

1 year ago

2.0.0-alpha.1

1 year ago

1.4.0

2 years ago

1.4.0-rc1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

1.0.0-rc1

2 years ago

0.13.2

2 years ago

0.13.1

2 years ago