Connect is a family of libraries for building type-safe APIs across different languages and platforms. The @connectrpc/connect package provides TypeScript support for web browsers and Node.js.
It follows a schema-first approach using Protocol Buffers. Once a schema is defined, code generation produces type-safe servers and clients. While the RPCs are type-safe end-to-end, they use regular HTTP under the hood, making them compatible with standard tools like curl and visible in network inspectors.
Connect supports three protocols:
- gRPC
- gRPC-web
- Connect protocol: An optimized protocol for the web.
This allows for high interoperability between Node.js services and clients running in web browsers, terminals, or native mobile environments.
service ElizaService {
rpc Say(SayRequest) returns (SayResponse) {}
}
const answer = await eliza.say({ sentence: "I feel happy." });
console.log(answer);
// {sentence: 'When you feel happy, what do you do?'}
curl \
--header 'Content-Type: application/json' \
--data '{"sentence": "I feel happy."}' \
https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say