Avatar (Fabio Alessandro Locati|Fale)'s blog

Inject DB connections in Golang gRPC API

March 21, 2022

One of the first issues that I had to solve when I started to use gRPC was how to inject a DB connection pool to the function handling the request. The DB connection injection is needed because creating a new SQL connection every time there is a new gRPC request (and tearing it down at the end) is a massive waste of resources. Also, this approach could limit the scalability of the API since the database probably has a limited number of connections it will accept.

Read More

gRPC-Gateway 2 in Fedora

February 22, 2022

gRPC is a very nice technology that allows the implementation of efficient APIs in a very efficient way. Thanks to gRPC and protobuf, you do not have to write much boilerplate code since the boilerplate code is generated automatically from the proto file. This works perfectly until both your client and server can perform gRPC calls. Luckily most of the languages have no issue with this. Still, the big exception is JavaScript (and other languages that will compile to JS, such as TypeScript) running in a browser.

Read More

CORS headers with gRPC-Gateway

July 28, 2021

A few years ago, I wrote a blog post on managing CORS headers with Negroni. Lately, I’ve created a new API server that needed to be accessible from the browser, but this time I used a different technology, more precisely gRPC-Gateway.

Few months after I wrote that blog post, I stopped writing new REST services by hand. I did not rewrite all the services that used the old paradigm just because they needed a fix or a new feature, but for all new services, I moved to gRPC with gRPC-Gateway.

Read More