O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works…

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

Next, executing a GET request with the path prefix as /v1 from the command line as follows, will give you a list of one set of employees:

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

 Here, executing a GET request with path prefix as /v2 will give you a list of another set of employees, as follows:

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

Sometimes, while designing the REST URL, we prefer to return the default data if the client queries the endpoint ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required