gRPC-Web with Golang and VueJS: An alternative to REST and GraphQL

gRPC-Web is a JavaScript client library that enables web apps to communicate directly with gRPC backend services, without requiring an HTTP server to act as an intermediary.

With gRPC-Web, you can now easily build truly end-to-end gRPC application architectures by defining your client and server-side data types and service interfaces with Protocol Buffers.

gRPC is a super-fast, super-efficient Remote Procedure Call (RPC) system that will make your microservices talk to each other. You can found more details in the official gRPC documentation and my previous post Building microservices in Go and Python using gRPC.

gRPC-Web, just like gRPC, lets you define the service “contract” between client (web) and backend gRPC services using Protocol Buffers. The client can then be auto generated. This development process removes the need to manage concerns such as creating custom JSON seralization and deserialization logic, wrangling HTTP status codes, managing content type negotiation etc.

Advantages of using gRPC-Web

End-to-end gRPC: Enables you to craft your entire RPC pipeline using Protocol Buffers. Your client can interacty directlly with one or more gRPC servers, just calling the definied functions.

Tighter coordination between frontend and backend teams: With the entire RPC pipeline defined using Protocol Buffers, you no longer need to have your “microservices teams” alongside your “client team.” The client-backend interaction is just one more gRPC layer amongst others.

Easily generate client libraries: All of your service’s client libraries can be gRPC libraries. Need client libraries for Rust, Python, Java, and 4 other languages? You no longer need to write HTTP clients for all of them.

The full source code using Golang and VueJS (Quasar Framework) can be found in my GitHub repository.

Conclusion

Now you are wondering “Should I adopt gRPC?”

gRPC is a robust architecture that has several supporters. Companies like Google, Netflix and Dropbox already use it in production. With a low learning curve, new developers on a gRPC project can be productive quickly. The definition of types and services in Protocol Buffer works as documentation too - whoever consumes the service gets to know what to send in the request and what can be received in the response.

gRPC-Web is an excellent option for web developers. It brings portability, excellent performance and a sophisticated protocol for use on the web or mobile front-end.