DEV Community

Philip Perry
Philip Perry

Posted on

Why we chose the Go Huma framework to develop our API endpoints

At the company where I work as a software engineer, we are in the process of developing an API that communicates with our micro services and will be used by our own products as well as being an API that our clients can use. Our overall deciding factor for choosing Golang for this was speed. Apart from fast execution time, Go also offers low memory consumption and efficient concurrency.

When it came to the first step of specifying the endpoints, we were looking for a solution to do so in code as we wanted to avoid a discrepancy between code and documentation. Our CEO had used the same approach using Python FastApi, so we googled for a FastApi solution for Go and came across Huma. With Huma one can automatically generate OpenAPI documentation from code and it generates a nice-looking documentation using stoplight elements. It generates the JSON schema from Go types and uses static typing for path/query/header params, bodies, response headers, etc. It does input model validation & error handling automatically based on the json schema.

We’ve found the framework fairly flexible and it allows for instance to use one own's router, although we just stuck with Chi which it uses as the default one. There are some downsides, for instance it doesn’t seem to support array query parameters, so we’re separating filters by comma. But that hasn’t been a deal breaker.

I plan to write more about my experience and learnings with Go Huma in future posts, but so far I have found it fit for purpose.

Top comments (0)