Creating a functional RESTful server
This section illustrates how to develop a RESTful server in Go given a REST API. The biggest difference between the presented RESTful service and the statistics application created in Chapter 9, Building Web Services, is that the RESTful service uses JSON messages for interacting with its clients, whereas the statistics application interacts and works using plain text messages.
If you are thinking of using net/http
for the implementation of the RESTful server, please do not do so without first thinking about the requirements of your server! This implementation uses the gorilla/mux
package, which is a much better choice because it supports subrouters – more about that in the Using gorilla/mux subsection. However, net/http
is still powerful and can be useful for many REST requirements.
The purpose of the RESTful server is to implement a login/authentication system. The purpose of the login system is to keep track of the users who are...