Knowing how to create a client library for your microservice is almost as important as knowing how to create the microservice itself. Some people question whether or not client libraries are actually necessary, and say that it’s enough to just describe the external interface and let the users of the microservice implement their own interaction protocol.
We strongly recommend the use of client libraries due to the following:
To avoid running into problems, we recommend following the rules below:
As we mentioned earlier, it’s highly recommended to implement mock versions of clients, as well as random data generators for simplifying the process of writing unit tests. And all mock clients should be tested using the same tests that are used to test the real clients, to exclude any and all differences in their implementation.
The client library that we will be creating in this tutorial is for the microservice described in the Data microservice tutorial. To better understand the client’s logic, it’s a good idea to familiarize yourself with that tutorial first, if you haven’t done so already.
To make it easier to follow along, we’ve broken up the tutorial on writing your first client library into the following steps:
Let's get started! Head on over to Step 1. Setting up the project.