Junior — Middle
What protocols did you use to obtain data in your last project?
sobes.tech AI
Answer from AI
In my last project in Go for data retrieval, I used the following protocols:
-
HTTP/HTTPS — the main protocol for interacting with REST API. Used the standard
net/httppackage for sending requests and receiving responses. -
gRPC — a remote procedure call protocol supporting HTTP/2, which allows efficient data exchange between services. Used for internal microservice communication.
-
WebSocket — for real-time data reception, for example, to update the UI when data on the server changes.
Example of a simple HTTP GET request in Go:
resp, err := http.Get("https://api.example.com/data")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
The choice of protocol depends on performance requirements, reliability, and the nature of the data.