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

Are you yet to start winning 😎

How Facebook Developer Circle Delhi became a thing

Dgraph: how to install and use with Go?

dockers caching layer with COPY and globs

Product Spotlight: Connected TV applications

The Connected TV product line for YinzCam.

vscode extensions that made me fall in love with dotnet

The Journey to Developer

Simple web analytics with Python and Pandas

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

How Golang DB migration tool work?

【Go】Implement SHA256, encryption and hashing in Go

[golang] How to use github for hosting self-updating binaries for your golang projects

Concurrency in Golang

Gopher image