Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/twirp-build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../README.md")]

use quote::{format_ident, quote};

/// Generates twirp services for protobuf rpc service definitions.
Expand Down
20 changes: 16 additions & 4 deletions crates/twirp/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `twirp-build`
# `twirp`

[Twirp is an RPC protocol](https://twitchtv.github.io/twirp/docs/spec_v7.html) based on HTTP and Protocol Buffers (proto). The protocol uses HTTP URLs to specify the RPC endpoints, and sends/receives proto messages as HTTP request/response bodies. Services are defined in a [.proto file](https://developers.google.com/protocol-buffers/docs/proto3), allowing easy implementation of RPC services with auto-generated clients and servers in different languages.

Expand Down Expand Up @@ -34,7 +34,11 @@ prost-build = "0.13"

Add a `build.rs` file to your project to compile the protos and generate Rust code:

```rust
<!--
`rust` gets syntax highlighting in GitHub UI and Rustdoc contexts
` ,ignore` (including the space) makes rust tests ignore the code without breaking syntax highlighting
-->
```rust ,ignore
fn main() {
let proto_source_files = ["./service.proto"];

Expand All @@ -55,7 +59,11 @@ This generates code that you can find in `target/build/your-project-*/out/exampl

Include the generated code, create a router, register your service, and then serve those routes in the hyper server:

```rust
<!--
`rust` gets syntax highlighting in GitHub UI and Rustdoc contexts
` ,ignore` (including the space) makes rust tests ignore the code without breaking syntax highlighting
-->
```rust ,ignore
mod haberdash {
include!(concat!(env!("OUT_DIR"), "/service.haberdash.v1.rs"));
}
Expand Down Expand Up @@ -93,7 +101,11 @@ This code creates an `axum::Router`, then hands it off to `axum::serve()` to han

On the client side, you also get a generated twirp client (based on the rpc endpoints in your proto). Include the generated code, create a client, and start making rpc calls:

``` rust
<!--
`rust` gets syntax highlighting in GitHub UI and Rustdoc contexts
` ,ignore` (including the space) makes rust tests ignore the code without breaking syntax highlighting
-->
```rust ,ignore
mod haberdash {
include!(concat!(env!("OUT_DIR"), "/service.haberdash.v1.rs"));
}
Expand Down
2 changes: 2 additions & 0 deletions crates/twirp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../README.md")]

pub mod client;
pub mod error;
pub mod headers;
Expand Down