JSON RPC using Gorilla RPC

We saw that the Gorilla toolkit helps us by providing many useful libraries. Then we explored Mux, Handlers, and now, the Gorilla RPC library. Using this, we can create RPC servers and clients that talk using a JSON instead of a custom reply pointer. Let us convert the preceding example into a much more useful one.

Consider this scenario. We have a JSON file on the server that has details of books (name, ID, author). The client requests book information by making an HTTP request. When the RPC server receives the request, it reads the file from the filesystem and parses it. If the given ID matches any book, then the server sends the information back to the client in the JSON format. We can install Gorilla RPC with ...

Get Building RESTful Web services with Go 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.