Now that we have an understanding of how a REST application should behave, let's build one! We shall start out by first building a simple web server, then design the books REST server by describing design decisions and API definitions, and finally build a REST server based on the design.
Fundamentals of a REST server
A simple web server
Go provides us with an inbuilt library for building web servers, net/http. For every endpoint we want to create on our server, we have to do two things:
- Create a handler function for the endpoint, which accepts two parameters, one for writing to response and one to handle the incoming Request.
- Register the endpoint using net/http.HandleFunc.
The following is a simple web server that...