How to implement gRPC in ASP.NET core

Hello Programmers,

I am final year student and I am creating gRPC service project in ASP NET Core. I took the help of online tutorials on gRPC + ASP.NET Core. I have some confusions that need to be solved. Please help me:

  1. What is the usefulness of gRPC over APIS ?
  2. What purpose it is going to solve in the industry.
  3. GRPC method of Bi-Directional Streaming is really confusing. I want to ask how to implement it for a database tasks of reading + Updating + inserting + deleting? I did not find any proper implementation of Bi-Directional Streaming method anywhere so please refer a good tutorial for beginners.
  4. How to call gRPC from JavaScript or jQuery?

Please let me know.

Thank you

This doesn’t really make sense: you build an [web] API using the RPC protocol, that’s how you interact with the underlying system your client is talking to. Do you mean RPC Vs REST (which is a set of architectural principles rather than a protocol, but it’s normally fair to compare them)

It’s an implementation of RPC that uses Protocol Buffers as the data interchange format, RPC has been around for a very long time (practically, about 40 years, theoretically, about 60). re “what problem does it solve”, if you want to call a method from a remote client as if you were calling the same method on the server, that’s what RPC does.

1 Like

Can you shed some knowledge about the implementation of Bi-Directional Streaming in gRPC. Thank you once again!

Hello @jsoftlucy,

I developed gRPC project in ASP NET Core and I can give you some important understanding of it.

Quoting from the official gRPC blog:

One of the key reasons to chose gRPC is because it uses HTTP/2, enabling applications to present both a HTTP 1.1 REST/JSON API and an efficient gRPC interface on a single TCP port. This provides developers with compatibility with the REST web ecosystem, while advancing a new, high-efficiency RPC protocol.

This working of gRPC can be understood by the below illustration:

gRPC calls can be of 4 types:

  • Unary
  • Server Streaming
  • Client Streaming
  • Bi-Directional Streaming

Bi-Directional Streaming

There is no concept of of Bi-Directional Streaming calls in REST API. This concept has come in gRPC and is very powerful.

In a bi-directional streaming, the call is initiated by the client invoking the method and the server receiving the client metadata, method name, and deadline. The server can choose to send back its initial metadata or wait for the client to start streaming messages.

So you can call it a combination of Server and Client streaming.

The understanding of Bi-Directional call in ASP.NET Core will depend on your understanding of Unary, Client & Server streaming so make sure you first learn Unary call then move to Server & Client streaming call and then only implement Bi-Directional call.

Thank You

1 Like