Grpc server for learning purposes

I wrote a GRPC server with basic features to support my aboratories, written articles, and videos it provides a sample of unary call, client streaming, server streaming and bidirectional streaming.

All the samples are “Hello world like” but once you h…


This content originally appeared on DEV Community and was authored by Jhonatan Morais

I wrote a GRPC server with basic features to support my aboratories, written articles, and videos it provides a sample of unary call, client streaming, server streaming and bidirectional streaming.

All the samples are "Hello world like" but once you have the project structure is possible to extend it to any purpose.

And I want to share it here. the image src code is available in my github

How to use the image:

docker run --rm --name grpc -p 50051:50051 getjv/go-grpc-server

Exploring server calls with grpcURL

gRPCurl is a super handy tool, and the main commands are:

  • grpcurl -plaintext [::]:50051 list – lists the available services.
  • grpcurl -plaintext [::]:50051 describe <ServiceName> – provides more information about the available service.
  • grpcurl -plaintext -d '<JSON-Payload>' [::]:50051 <ServiceName.MethodName> – makes a direct call to a method with a payload.

Use samples:

Hello sample: it's a unary call with single request single response.

grpcurl -plaintext -d '{"name": "jhonatan"}' [::]:50051 helloworld.Greeter.SayHello

Server Streaming sample: it's a server streaming sample with 1 request and 10 messages from server

grpcurl -d '{"name": "Cliente"}' -plaintext localhost:50051 helloworld.Greeter/StreamGreetings

Client Streaming sample: it's a client streaming sample with 10 client requests and 1 message from server
Here the steps are a bit different:

  • Open the channel with:
grpcurl -plaintext -d @ localhost:50051 helloworld.Greeter/EchoGreetings
  • the terminal will wait the input give the objects bellow and press enter:
{"name": "Alice"}
{"name": "Bob"}
{"name": "Charlie"}
  • Now press CTRL+D to notify all was sent. Server will send you the final confirmation.

Bi-directional streaming: this is the most advanced sample an open channel to both sides keeping interacting
to test execute:

  • Open the channel with:
      grpcurl -plaintext -d @ localhost:50051 helloworld.Greeter/OpenGreetings
  • the terminal will wait the input give the objects bellow and press enter:
      {"name": "Alice"}
  • After each enter Server will send you a confirmation.
  • Now press CTRL+D to notify you are done.


This content originally appeared on DEV Community and was authored by Jhonatan Morais


Print Share Comment Cite Upload Translate Updates
APA

Jhonatan Morais | Sciencx (2025-03-09T13:18:59+00:00) Grpc server for learning purposes. Retrieved from https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/

MLA
" » Grpc server for learning purposes." Jhonatan Morais | Sciencx - Sunday March 9, 2025, https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/
HARVARD
Jhonatan Morais | Sciencx Sunday March 9, 2025 » Grpc server for learning purposes., viewed ,<https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/>
VANCOUVER
Jhonatan Morais | Sciencx - » Grpc server for learning purposes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/
CHICAGO
" » Grpc server for learning purposes." Jhonatan Morais | Sciencx - Accessed . https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/
IEEE
" » Grpc server for learning purposes." Jhonatan Morais | Sciencx [Online]. Available: https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/. [Accessed: ]
rf:citation
» Grpc server for learning purposes | Jhonatan Morais | Sciencx | https://www.scien.cx/2025/03/09/grpc-server-for-learning-purposes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.