Yesterday I gave a presentation at the Go User Group Hamburg called “Talking to HTTP/JSON APIs with Go”. As promised, I’ve published my slides today. Unfortunately, talks.godoc.org does not allow running Go code embedded in slides, but I’m a kind person and have released the slide sources as well. (If you’re curious, I’ve used the very simple and very cool present format.)
- Download JSON data via HTTP using
http.Get. Read the HTTP body with
json.Unmarshalto decode JSON data into Go structs (with optional struct tags).
- For unit testing, start an internal web server with
httptest.NewServerand provide a
http.HandlerFuncthat serves test data on request.
- Table-driven tests are awesome!
- Sometimes GitHub is down.