O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fetching the list of products

Now that we've seen how the client-side route handler function works, let's take a look at the FetchProducts function that is used to make the XHR call to the server and gather the list of products to display on the page:

func FetchProducts(productsChannel chan []*models.Product) {  data, err := xhr.Send("GET", "/restapi/get-products", nil)  if err != nil {    println("Encountered error: ", err)    return  }  var products []*models.Product  json.NewDecoder(strings.NewReader(string(data))).Decode(&products)  productsChannel <- products}

Here, we use the xhr package to make XHR calls to the server. We call the Send function from the xhr package and specify that our request will be using the GET method, and we will be making ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required