ConnectRPC - Rust implementation of Connect protocol
About
ConnectRPC is a Rust implementation of the Connect protocol, a modern and efficient RPC framework designed for building scalable and high-performance applications. It supports multiple transport protocols, including HTTP/1.1, HTTP/2, and gRPC, making it versatile for various use cases.
⚠️ This project is in early development. It only supports unary and unary get requests at the moment, and is heavily being tested and iterated on. Expect breaking changes.
Features
The library offers multiple components and features to facilitate the development of RPC clients and servers:
Components:
- Reqwest Client: Built on top of the popular Reqwest HTTP client for ease of use and reliability
- Axum Server: Implementation used for axum servers.
- Code Generation: Tools to generate client and server code from protobuf definitions.
Features:
- Unary Calls: Support for unary RPC calls.
- Unary Get Calls: Support for unary GET RPC calls.
- Streaming Calls: (Planned) Support for server-side, client-side, and bidirectional streaming RPC calls.
- Middleware Support: (Planned) Ability to add middleware for logging, authentication, etc. MTLs is supported since reqwest supports it.
Usage
Define services and messages in a proto file:
syntax = "proto3";
package hello;
message HelloRequest { optional string name = 1; }
message GoodbyeRequest { optional string name = 1; }
message HelloResponse { string message = 1; }
message GoodbyeResponse { string message = 1; }
service HelloWorldService {
rpc SayHello(HelloRequest) returns (HelloResponse) {}
rpc SayGoodbye(GoodbyeRequest) returns (GoodbyeResponse) {}
}
You need to add connectrpc-build to your build-dependencies in Cargo.toml:
[]
= "0.1"
= "0.1.2"
Then, create a build.rs file to generate the necessary code. More complex examples will be included in the examples directory, but here is a simple snippet:
use ;
use Settings;
This will generate the necessary client and server code in src/lib.rs. If you are building a client only, you can specify the generation features in the Settings:
use ;
use ;
Note: Depending on the features you enable, you might need to include additional dependencies in your `Cargo.toml`. For example, if you are using the Reqwest client, ensure that you have the `reqwest` crate included.
```toml
name = "your_crate_name"
version = "0.1.0"
edition = "2024"
# Required dependencies for ConnectRPC
pbjson = "0.8.0"
pbjson-types = "0.8.0"
prost = "0.14"
serde =
connectrpc =
# Dependencies you need
reqwest =
# Required for code generation
connectrpc-build = "0.1"
protoc-fetcher = "0.1.2"
Thanks
This project is based on the works of:
I'm grateful for their contributions to the Rust ecosystem and their pioneering work in implementing the Connect protocol. Their efforts have laid the groundwork for this project, and I hope to build upon their successes to create a robust and efficient ConnectRPC implementation in Rust.
License
This project is licensed under the MIT License. See the LICENSE file for details.