Top Related Projects
gRPC Web implementation for Golang and TypeScript
The TypeScript implementation of Connect: Protobuf RPC that works.
A simple RPC framework with protobuf service definitions
gRPC for Node.js
Quick Overview
connect-es
is a library that provides a simple and efficient way to interact with Elasticsearch from a Node.js environment. It abstracts away the complexity of the Elasticsearch client, allowing developers to focus on their application logic rather than the intricacies of the Elasticsearch API.
Pros
- Simplicity:
connect-es
offers a straightforward and easy-to-use API, making it accessible for developers of all skill levels. - Efficiency: The library is designed to be lightweight and performant, with a focus on minimizing overhead and maximizing throughput.
- Flexibility:
connect-es
supports a wide range of Elasticsearch features and operations, allowing developers to tailor it to their specific needs. - Reliability: The library is well-tested and maintained, ensuring a stable and dependable experience for users.
Cons
- Limited Functionality: While
connect-es
covers a wide range of Elasticsearch features, it may not provide the same level of granular control as the official Elasticsearch client. - Dependency on Elasticsearch: The library is tightly coupled with Elasticsearch, which means that developers are reliant on the continued development and support of the Elasticsearch ecosystem.
- Potential Learning Curve: Developers who are new to Elasticsearch may need to invest time in understanding the underlying concepts and terminology before they can effectively use
connect-es
. - Lack of Advanced Features: The library may not offer the same level of advanced features and customization options as some other Elasticsearch client libraries.
Code Examples
// Performing a simple search
const { Client } = require('connect-es');
const client = new Client({
node: 'http://localhost:9200',
});
const result = await client.search({
index: 'my-index',
query: {
match: {
title: 'hello world',
},
},
});
console.log(result.hits.hits);
// Indexing a document
const { Client } = require('connect-es');
const client = new Client({
node: 'http://localhost:9200',
});
const document = {
title: 'My Document',
content: 'This is the content of my document.',
};
const result = await client.index({
index: 'my-index',
document,
});
console.log(result);
// Deleting a document
const { Client } = require('connect-es');
const client = new Client({
node: 'http://localhost:9200',
});
const result = await client.delete({
index: 'my-index',
id: 'my-document-id',
});
console.log(result);
Getting Started
To get started with connect-es
, follow these steps:
- Install the library using npm or yarn:
npm install connect-es
- Import the
Client
class from theconnect-es
module:
const { Client } = require('connect-es');
- Create a new
Client
instance, providing the URL of your Elasticsearch cluster:
const client = new Client({
node: 'http://localhost:9200',
});
- Use the client to interact with Elasticsearch, such as performing searches, indexing documents, or deleting data:
const result = await client.search({
index: 'my-index',
query: {
match: {
title: 'hello world',
},
},
});
console.log(result.hits.hits);
That's it! You're now ready to start using connect-es
to interact with your Elasticsearch cluster from your Node.js application.
Competitor Comparisons
gRPC Web implementation for Golang and TypeScript
Pros of grpc-web
- More mature and widely adopted in the gRPC ecosystem
- Supports bidirectional streaming
- Offers compatibility with existing gRPC backends
Cons of grpc-web
- Requires additional setup and configuration
- Limited browser support without polyfills
- Larger bundle size due to Protocol Buffers dependency
Code Comparison
grpc-web:
const { HelloRequest, HelloReply } = require('./helloworld_pb.js');
const { GreeterClient } = require('./helloworld_grpc_web_pb.js');
const client = new GreeterClient('http://localhost:8080');
const request = new HelloRequest();
request.setName('World');
client.sayHello(request, {}, (err, response) => {
console.log(response.getMessage());
});
connect-es:
import { createPromiseClient } from "@connectrpc/connect";
import { createGrpcWebTransport } from "@connectrpc/connect-web";
import { GreeterService } from "./gen/helloworld_connect.js";
const transport = createGrpcWebTransport({ baseUrl: "http://localhost:8080" });
const client = createPromiseClient(GreeterService, transport);
const response = await client.sayHello({ name: "World" });
console.log(response.message);
connect-es offers a more streamlined API with less boilerplate code and built-in Promise support. It also has a smaller bundle size and better TypeScript integration. However, grpc-web may be preferred for projects already using gRPC or requiring full compatibility with existing gRPC backends.
The TypeScript implementation of Connect: Protobuf RPC that works.
Pros of connect-es
- Designed specifically for ECMAScript environments, offering better compatibility with modern JavaScript and TypeScript projects
- Provides a more streamlined API tailored for ES6+ syntax and features
- Potentially smaller bundle size due to focus on ES modules
Cons of connect-es
- May have less comprehensive documentation compared to the main Connect project
- Potentially fewer community contributions and third-party integrations
- Could have a smaller ecosystem of plugins and extensions
Code Comparison
connect-es:
import { createPromiseClient } from "@connectrpc/connect";
import { createGrpcWebTransport } from "@connectrpc/connect-web";
import { ElizaService } from "./gen/eliza_connect";
const transport = createGrpcWebTransport({ baseUrl: "https://demo.connectrpc.com" });
const client = createPromiseClient(ElizaService, transport);
connect:
const { ConnectRouter } = require("@connectrpc/connect");
const { ElizaService } = require("./gen/eliza_connect");
const router = new ConnectRouter();
router.service(ElizaService, {
// Service implementation
});
Note: The code comparison is approximate, as the exact implementation details may vary between the two repositories.
A simple RPC framework with protobuf service definitions
Pros of Twirp
- Simpler and more lightweight, focusing on RPC over HTTP 1.1
- Better suited for microservices and internal communication
- Easier to set up and use for developers new to RPC frameworks
Cons of Twirp
- Limited to Protocol Buffers for serialization
- Lacks built-in support for streaming and bidirectional communication
- Less flexible in terms of transport protocols compared to Connect
Code Comparison
Twirp service definition:
service Haberdasher {
rpc MakeHat(Size) returns (Hat);
}
Connect service definition:
service Haberdasher {
rpc MakeHat(MakeHatRequest) returns (MakeHatResponse);
rpc StreamHats(StreamHatsRequest) returns (stream Hat);
}
The code comparison shows that Connect supports streaming (as seen in the StreamHats
method), while Twirp is limited to unary RPC calls.
Connect offers a more feature-rich and flexible approach to RPC, supporting various protocols and serialization formats. It's better suited for complex, large-scale applications with diverse communication needs. Twirp, on the other hand, provides a simpler, more focused solution that excels in microservices architectures and scenarios where lightweight, HTTP-based RPC is sufficient.
gRPC for Node.js
Pros of grpc-node
- More mature and widely adopted in the Node.js ecosystem
- Supports bidirectional streaming, which connect-es currently lacks
- Offers native gRPC implementation for potentially better performance
Cons of grpc-node
- Requires protocol buffers for schema definition, adding complexity
- Heavier dependency footprint and more challenging to set up
- Limited browser support, primarily focused on server-side Node.js
Code Comparison
connect-es:
import { createPromiseClient } from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect";
const transport = createGrpcTransport({
httpVersion: "2",
baseUrl: "https://demo.connectrpc.com",
});
const client = createPromiseClient(ElizaService, transport);
grpc-node:
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const packageDefinition = protoLoader.loadSync('eliza.proto');
const elizaProto = grpc.loadPackageDefinition(packageDefinition).eliza;
const client = new elizaProto.ElizaService('localhost:50051', grpc.credentials.createInsecure());
The code examples demonstrate the client setup process for both libraries. connect-es offers a more straightforward and TypeScript-friendly approach, while grpc-node requires additional steps for protocol buffer loading and service definition.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Connect for ECMAScript
Connect is a family of libraries for building type-safe APIs with different languages and platforms. @connectrpc/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 Remote Procedure Call 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 RPC three 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.
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 serve your Connect RPCs with vanilla Node.js, or use our server plugins
for Fastify, Next.js, and Express. We support Node.js v16 and later with
the builtin http
and http2
modules.
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
- @connectrpc/connect: RPC clients and servers for your schema (source code).
- @connectrpc/protoc-gen-connect-es: Code generator plugin for the services in your schema (source code).
- @connectrpc/connect-web: Adapters for web browsers, and any other platform that has the fetch API on board.
- @connectrpc/connect-node: Serve RPCs on vanilla Node.js servers. Call RPCs with any protocol.
- @connectrpc/connect-fastify: Plug your services into a Fastify server.
- @connectrpc/connect-next: Serve your RPCs with Next.js API routes.
- @connectrpc/connect-express: Adds your services to an Express server.
The libraries and the generated code are compatible with ES2017 and TypeScript 4.1.
Ecosystem
- examples-es: Examples for using Connect with various TypeScript web frameworks and tooling
- connect-query-es: TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers
- connect-playwright-es: Playwright tests for your Connect application
- connect-swift: Idiomatic gRPC & Connect RPCs for Swift
- connect-go: Go implementation of gRPC, gRPC-Web, and Connect
- examples-go: Example RPC service powering https://demo.connectrpc.com and built with connect-go
- conformance: gRPC-Web and Connect interoperability tests
- Buf Studio: web UI for ad-hoc RPCs
Status: Stable
All packages are stable and have reached a major version release.
Legal
Offered under the Apache 2 license.
Top Related Projects
gRPC Web implementation for Golang and TypeScript
The TypeScript implementation of Connect: Protobuf RPC that works.
A simple RPC framework with protobuf service definitions
gRPC for Node.js
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot