How it works...

Once we run the program, the HTTP server will start locally listening on port 8080.

Next, executing a GET request from the command line as follows will give you a list of all the employees:

$ curl -X GET http://localhost:8080/employees[{"id":"1","firstName":"Foo","lastName":"Bar"},{"id":"2","firstName":"Baz","lastName":"Qux"}]

Here, executing a GET request for a particular employee ID from the command line as follows, will give you the employee details for the corresponding ID:

$ curl -X GET http://localhost:8080/employee/1 {"id":"1","firstName":"Foo","lastName":"Bar"}

Let’s understand the program we have written:

  1. We used import ("encoding/json" "log" "net/http" "strconv" "github.com/gorilla/mux"). Here, we imported github.com/gorilla/mux ...

Get Go Web Development Cookbook 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.