Writing a client for a REST API
Writing a client for a REST API will not only help you better understand the API in question, but also gives you a useful tool for all future applications using that API. This will explore structuring a client and show some strategies that you can immediately take advantage of.
For this client, we'll assume that the authentication is handled by basic auth, but it would also be possible to hit an endpoint to retrieve a token, and so on. For the sake of simplicity, we'll assume our API exposes one endpoint, GetGoogle()
, which returns that status code returned from doing a GET
request to https://www.google.com.
Getting ready
Refer to the Getting ready section of the Initializing, storing, and passing http.Client structs recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter6/rest
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter6...