Universal gRPC client demonstration [Evans]

Create a simple gRPC server

Sample repository

Defining calls

// it is important to declare syntax version
syntax = "proto3";
service BookShelf {
rpc AddBook(AddBookRequest) returns (AddBookResponse) {}
rpc ListBook (ListBooksRequest) returns (ListBooksResponse) {}
rpc DelBook (DelBookRequest) returns (DelBookResponse){}
rpc FindBook (FindBookRequest) returns (FindBookResponse){}
}
message AddBookRequest {
BookInfo book = 1;
message BookInfo {
string isbn =1;
string name =2;
string author=3;
string addedBy=4;
}
}message AddBookResponse {
string message = 1;
}
message ListBooksRequest {
// no need to have anything
// could be extended to list books based on category ...
}
message ListBooksResponse {
repeated BookInfo books =1;
message BookInfo {
string isbn =1;
string name =2;
string author=3;
string addedBy=4;
}
}
message DelBookRequest {
string isbn =1;
}
message DelBookResponse {
string message =1;
}
message FindBookRequest {
string isbn =1;
}
message FindBookResponse {
Book book = 1;
message Book {
string isbn =1;
string name =2;
string author=3;
string addedBy=4;
}
}

Compile Proto file

$  protoc -I proto/ proto/bs.proto --go_out=plugins=grpc:proto

Run gRPC server

$ go run server/main.go
BookShelf gRPC server is running ....

Demonstration of EVANS

❯ evans -r -p 9000  ______
| ____|
| |__ __ __ __ _ _ __ ___
| __| \ \ / / / _. | | '_ \ / __|
| |____ \ V / | (_| | | | | | \__ \
|______| \_/ \__,_| |_| |_| |___/
more expressive universal gRPC clientBookShelf@127.0.0.1:9000> show services +-----------+----------+------------------+-------------------+
| SERVICE | RPC | REQUEST TYPE | RESPONSE TYPE |
+-----------+----------+------------------+-------------------+
| BookShelf | AddBook | AddBookRequest | AddBookResponse |
| BookShelf | ListBook | ListBooksRequest | ListBooksResponse |
| BookShelf | DelBook | DelBookRequest | DelBookResponse |
| BookShelf | FindBook | FindBookRequest | FindBookResponse |
+-----------+----------+------------------+-------------------+
BookShelf@127.0.0.1:9000>

--

--

--

Software Engineer at Aalborg University, Denmark

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Best API To Get Aluminium Prices From Fastmarkets

How To Get The Hub Code Of Airlines Using An API

How Programmers Can Help Fight Racial Injustice

Alternatives to GoldPricez for Precious Metal Rates

Varjo Aero and Triple Monitors

𝐏𝐚𝐧𝐝𝐨 𝐁𝐫𝐨𝐰𝐬𝐞𝐫 | Database update.

UkeChords with Sinatra

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmet Türkmen

Ahmet Türkmen

Software Engineer at Aalborg University, Denmark

More from Medium

Concurrency [with sample project] in Golang

Golang Testify: require vs assert

Getting started with GO Programming Language — Part Two

Build simple gRPC server with Golang