title: Parsing REST API Response
body: <p>I am new to golang. I was writing a program to parse the json response of the API: <a href="https://httpbin.org/get" rel="nofollow noreferrer">https://httpbin.org/get</a>. I have used the following code to parse the response:</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
      "net/http"
      "os"
  )
  
  type Headers struct {
      Close  string `json:"Connection"`
      Accept string `json:"Accept"`
  }
  
  type apiResponse struct {
      Header Headers `json:"headers"`
      URL    string  `json:"url"`
  }
  
  func main() {
      apiRoot := "https://httpbin.org/get"
      req, err := http.NewRequest("GET", apiRoot, nil)
      if err != nil {
          fmt.Println("Couldn't prepare request")
          os.Exit(1)
      }
      response, err := http.DefaultClient.Do(req)
      if err != nil {
          fmt.Println(err)
          os.Exit(1)
      }
      defer response.Body.Close()
      var responseStruct apiResponse
      err = json.NewDecoder(response.Body).Decode(&amp;responseStruct)
      if err != nil {
          fmt.Println(err)
          os.Exit(1)
      }
  
      fmt.Printf("%v\n", responseStruct)
  }
  </code></pre>
  
  <p>When I run this code the output is:</p>
  
  <pre><code>$ go run parse.go
  {{close } https://httpbin.org/get}
  </code></pre>
  
  <p>From the output, as we can see the "Accept" key in json response is not decoded. Why is it so? How can I parse that string from response body?</p>