Writing a client for a REST API will not only help you better understand the API in question, it will also give you a useful tool for all future applications using that API. This recipe 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 the basic auth, but it should also be possible to hit an endpoint to retrieve a token, and so on. For the sake of simplicity, we'll assume that our API exposes one endpoint, GetGoogle(), which returns that status code returned from doing a GET request to https://www.google.com.
How to do it...
These steps cover writing and running of your application:
- From your Terminal or console application, create a new directory called ~/projects/go-programming-cookbook/chapter7/rest, and navigate to this directory.
- Run the following command: ...