Displaying Go App In The Browser <p>I wrote an app that makes a request to an API and gets a JSON response. When I run the app it displays the json in the terminal.</p> <pre><code>go run main.go </code></pre> <p>I want to make this run in the browser and I found this, which allowed me to print a string to the browser. </p> <pre><code> func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "This is a string") } </code></pre> <p>Then in <code>main</code></p> <pre><code>http.HandleFunc("/", handler) log.Fatal(http.ListenAndServe("localhost:8000", nil)) </code></pre> <p>Now that I have a string being printed to the screen and I have a json response coming from the api I am using, how can I add the json response to the browser instead of the string? </p> <p>Would it be best to put the response into a string then just bring it to the browser?</p> <p>Currently I am printing the json response to the terminal like this,</p> <pre><code>type Payload struct { Page int Results []Data } type Data struct { PosterPath string `json:"poster_path"` Adult bool `json:"adult"` Overview string `json:"overview"` ReleaseDate string `json:"release_date"` GenreIds []int `json:"genre_ids"` Id int `json:"id"` OriginalTitle string `json:"original_title"` OriginalLanguage string `json:"original_language"` Title string `json:"title"` BackdropPath string `json:"backdrop_path"` Popularity float64 `json:"popularity"` VoteCount int `json:"vote_count"` Video bool `json:"video"` VoteAverage float64 `json:"vote_average"` } </code></pre> <p>Then inside <code>main()</code> I do this,</p> <pre><code> for i := 0; i &lt; len(p.Results); i++ { fmt.Println( ImgUrl+p.Results[i].PosterPath, "\n", p.Results[i].Adult, p.Results[i].Overview, "\n", p.Results[i].ReleaseDate, p.Results[i].GenreIds, "\n", p.Results[i].Id, p.Results[i].OriginalTitle, "\n", p.Results[i].OriginalLanguage, p.Results[i].Title, "\n", ImgUrl+p.Results[i].BackdropPath, p.Results[i].Popularity, "\n", p.Results[i].VoteCount, p.Results[i].Video, "\n", p.Results[i].VoteAverage, ) </code></pre> <p>What would be the Go way to do this for building web applications? My end goal here is to take user input and recreate my api call based on the information they provide.</p>