Author:

Moncef AOUDIA

 

From OpenRPC to gRPC, the Rust way

07/02/2023

Summary  📋

  1. OpenRPC, OpenAPI & gRPC
  2. protobuf
  3. ToolBox
  4. OpenRPC to OpenAPI
  5. OpenAPI to gRPC
  6. Tonic + Prost
  7. Demo
  8. Questions

gRPC  📝

OpenAPI &

OpenRPC,

{
    "openrpc": "1.2.4",
    "info": {
    },
    "methods": {},
    "components": {
        "schemas": {},
        "contentDescriptors": {}
    }
}
{
    "openapi": "3.1.0",
    "info": {
    },
    "paths": {},
    "components": {
        "schemas": {}
    },
    "tags": []
}
syntax = "proto3";

package hello;

service HelloService {
  rpc SayHello (HelloRequest) returns (HelloResponse);
}

message HelloRequest {
  string greeting = 1;
}

message HelloResponse {
  string reply = 1;
}

OpenAPI, OpenRPC & gRPC  📝

Protobuf & gRPC  ✉️

Protobuf & gRPC  ✉️

syntax = "proto3";

package ecommerce.v1;

service ProductInfo {
   rpc getProduct(ProductID) returns (Product);
}

message Product {
   string id = 1;
   string name = 2;
   string description = 3;
   float price = 4;
}

message ProductID {
    string value = 1;
}

Message Encoding Using Protocol Buffers

Protobuf & gRPC  ✉️

message Product {
    int32 id = 1;
    float price = 2;
}

Protobuf & gRPC  ✉️

message Product {
    int32 id = 1;
    float price = 2;
}

Available wire types and corresponding field types

Protobuf & gRPC  ✉️

message OrderId {
    string value = 1;
}

Length-Prefixed Message Framing

Protobuf & gRPC  ✉️

gRPC native implementation architecture

Protobuf & gRPC  ✉️

How gRPC semantics relate to HTTP/2

Protobuf & gRPC  ✉️

Simple RPC

Protobuf & gRPC  ✉️

Server-streaming RPC

Protobuf & gRPC  ✉️

Client-streaming RPC

Protobuf & gRPC  ✉️

Bidirectional-streaming RPC

Toolbox  🧰

  • OpenRPC playground
  • OpenRPC VSCode
  • Protobuf VSCode
  • ApiCurio studio
  • protoc
  • gnostic
  • Prost
  • Tonic
  • Setup-protoc GitHub action

OpenRPC to OpenAPI ⚙️

ApiCurio studio: OpenAPI 2&3 contracts editor

OpenAPI to gRPC ⚙️

Gnostic gRPC plugin: OpenAPI v3.0 API description into a description of a gRPC service using the Protocol Buffers language.

gnostic openapi.json --grpc-out=MY_OUTPUP_FOLDER

Demo 🖼️

Sources 📚

Sources 📚

by Kasun Indrasiri, Danesh Kuruppu

Released January 2020

Publisher(s): O'Reilly Media, Inc.

ISBN: 9781492058335

Sources 📚

From OpenRPC to gRPC, the Rust way

By Moncef AOUDIA

From OpenRPC to gRPC, the Rust way

From OpenRPC to gRPC, the Rust way

  • 312