Structured Data
Once you have requested data from a server, the data returned can come in various formats. For example, if you send a request to packtpub.com
, it will return HTML data for the Packt website. While HTML data is useful for displaying websites, it isn't ideal for sending machine-readable data. A common data type used in web APIs is JSON. JSON provides a good structure for data that is both machine-readable and human-readable. Later, you will learn how to parse JSON and make use of it using Go.
Exercise 14.02: Using the HTTP Client with Structured Data
In this exercise, you will parse structured JSON data in Go. The server will return JSON data and you will use the json.Unmarshal
function to parse the data and put it into a struct:
- Create a new directory,
Exercise14.02
, on your GOPATH. Within that directory, create two more directories,server
andclient
. Then, within theserver
directory, create a file calledserver.go
and write the following code:package...