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 17.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 them into a struct:
- Create a new directory,
Exercise17.02
. Within that directory, create two more directories,server
andclient
. Then, within theserver
directory, create a file calledserver.go
and write the following code:package...