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  βœ‰οΈ

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

  • 912