How to develop a RESTful client in Go
OUR EXPERT
Mihalis Tsoukalos is a systems engineer and technical writer. He’s the author of Go Systems Programming and Mastering Go. You can reach him at @mactsouk.
The subject of this month’s tutorial is RESTful services. In particular, you’re going to learn how to develop a client for an existing RESTful server using the Go programming language. The client is going to be able to communicate with the RESTful server that we developed in part one (see LXF282), which means that the command line utility must support all server endpoints. Let’s get started.
The supported REST API
First, let’s recap what our REST API client needs to support. The REST API is defined on the server side, but remember that you don’t have to support all endpoints. What is important is to use the correct endpoints along with the expected HTTP methods and JSON records. Once again, we need to marshal and unmarshal JSON data when interacting with the RESTful server. However, we’re not going to discuss the JSON marshalling and unmarshalling process in this tutorial – if you don’t know how to do this, get hold of the previous tutorial.
As a reminder, the REST API that we need to support includes four endpoints. These endpoints are /time (GET HTTP method), /insert (POST HTTP method), /delete (DELETE HTTP method) and /list (GET HTTP method). Only /insert requires JSON input whereas /list returns an array of JSON records instead of single JSON records. Additionally, /delete requires user input to know
You’re reading a preview, subscribe to read more.
Start your free 30 days