Linux Format

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.

More from Linux Format

Linux Format1 min read
Vector Vexations
Why does MySQL not support vectors in its community edition? Generative AI is the hot topic in tech. GenAI relies on vector data. Yet Oracle has no plans to support vectors in the community edition of MySQL. If you want to try out vector data with ot
Linux Format5 min read
Tips For Managing Docker Containers
Everyone knows how containers revolutionised application building and deployment. Using a E disposable stack of containers that make up an app that aren’t using the docker-compose command to manage the stack are missing a trick. It allows the shippin
Linux Format1 min read
Wine For Wayland
2023 was a great year for the Wayland driver for Wine. The goal was to move forward from the experimental phase and make the driver a proper upstream component. A year later, after several merge requests, many people are now already able to use the l

Related