A JSON API server
Armed with the information from the last section, it is possible to use the HTTP package to create services over HTTP. Earlier we discussed the perils of creating services using raw TCP directly when we created a server for our global monetary currency service. In this section, we explore how to create an API server for the same service using HTTP as the underlying protocol. The new HTTP-based service has the following design goals:
- Use HTTP as the transport protocol
- Use JSON for structured communication between client and server
- Clients query the server for currency information using JSON-formatted requests
- The server respond using JSON-formatted responses
The following shows the code involved in the implementation of the new service. ...
Get Learning Go Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.