Crate implementing the needed runtime for the code generated by `twurst-build` in order to run [Twirp](https://twitchtv.github.io/twirp/docs/spec_v7.html) clients. ## Getting started To start you need first to have a gRPC `.proto` file (e.g. `service.proto`). Then build your proto files by creating a `build.rs` file with: ```rust,ignore fn main() -> std::io::Result<()> { twurst_build::TwirpBuilder::new() .with_client() .compile_protos(&["proto/service.proto"], &["proto"]) } ``` and add to your `Cargo.toml`: ```toml [dependencies] prost = "" prost-types = "" prost-reflect = "" twurst-client = { version = "", features=["reqwest-012"] } [build-dependencies] twurst-build = "" ``` Note that `protoc` must be available, see [`prost-build` documentation on this topic](https://docs.rs/prost-build/latest/prost_build/#sourcing-protoc). If you are using Nix, `nix-shell -p protobuf` is enough to provide `protoc`. Then you can use the Twirp client with: ```rust,ignore use twurst_client::TwirpHttpClient; mod proto { include!(concat!(env!("OUT_DIR"), "/example.rs")); // example is the name of your proto package } async fn main() { let twirp_client = TwirpHttpClient::new_using_reqwest_012("http://example.com/twirp"); let client = proto::ExampleServiceClient::new(twirp_client); // ExampleServiceClient is the name of the gRPC service let response = client.test(TestRequest {}).await?; // Does a Twirp request } ``` Note that you can custom the HTTP client with any [`tower`](https://docs.rs/tower) or [`tower-http`](https://docs.rs/tower-http) layer. For example to add a basic authorization header to all requests: ```rust,ignore use twurst_client::{TwirpHttpClient, Reqwest012Service}; use tower::ServiceBuilder; use tower_http::auth::AddAuthorizationLayer; fn main() { let twirp_client = TwirpHttpClient::new_with_base( ServiceBuilder::new() .layer(AddAuthorizationLayer::basic("username", "password")) .service(Reqwest012Service::from(reqwest::Client::new())) ); } ``` ## Cargo features - `reqwest-012` allows to use [`reqwest` 0.12](https://docs.rs/reqwest/0.12/) HTTP implementation. ## License Copyright 2024 Helsing GmbH Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.