Difference between Setting & Adding the Headers in HTTP API in Golang

While working with APIs, headers are an essential aspect. Sometimes we set them, or sometimes we consume them and make decisions. When I was exploring headers in Golang, I came across two methods. Headers.Set() & Headers.Add() Initially, I thought they were the same. But then I wondered if they are the same, then why two methods? Let鈥檚 understand. I will be using a proxy which will use Add & Set on headers, as shown below,...

January 18, 2023 路 2 min 路 Suraj Narwade

Why close the HTTP API response body in Golang? What if you don't...

In the previous article, we saw how to make the HTTP GET API request in Golang. While going through the example, we discussed closing the response body. In this article, Let鈥檚 discuss why it is essential to close the response body. What is the response body? The response body is a stream of data that is read from the server. Why should I close it? Ensure all data has been read and the resources associated with it are freed up....

January 14, 2023 路 2 min 路 Suraj Narwade

How to make an HTTP GET request in Golang?

Golang is one of the widely used languages for designing API Clients. While you design the client, one of the important aspects of the client is fetching the data from the API in some format using a GET request. Here鈥檚 the curl command example, which mimics the GET request which we will write code for in Golang, $ curl -XGET localhost:8080 {"message":"hello world !!!"} Note: I already have a basic webserver running, Hence I can get the output on localhost....

January 13, 2023 路 2 min 路 Suraj Narwade