Gopher with a hammer

Build http.request faster and simpler in Golang

Juan
2 min readMay 26, 2021

--

Whenever we use the ’http’ module to create a ‘client’ and do a REST call in a Golang application we should create a ‘request’ from the same module and define it like in the next snippet:

What about when we create other requests like a GET with headers and query parameters…

or a POST with body…

Looks easy right?… Yes, it is! But this is what we have implemented in every project and as a developer i hate to repeat code or take too long to write so thats why i’ve created a Go module to simplified the construction of http requests faster by applying the builder pattern.

Let see how the previous http request are made with this module, first a simple GET…

GET with headers and query parameters…

POST with body…

Overall

I know it won’t save you that much time but you’ll use a simpler and even syntax so you won’t have to know or remember how to add headers, set query parameters or marshal a body to JSON for your requests.

If you want to contribute with any feature/enhancement/fix feel free to open a Pull Request or an issue in the repository :)

For a full example check the the section ‘Example of use’.

--

--