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 to do it…

  1. Install the github.com/gorilla/mux and gopkg.in/resty.v1 packages using the go get command, as follows:
$ go get github.com/gorilla/mux$ go get -u gopkg.in/resty.v1
  1. Create http-rest-client.go where we will define handlers that call resty handlers, such as GET, POST, PUT, and DELETE, get the response from the REST service, and write it to an HTTP response stream, as follows:
package mainimport (  "encoding/json"  "fmt"  "log"  "net/http"  "github.com/gorilla/mux"  resty "gopkg.in/resty.v1")const (  CONN_HOST = "localhost"  CONN_PORT = "8090")const WEB_SERVICE_HOST string = "http://localhost:8080"type Employee struct {  Id string `json:"id"`  FirstName string `json:"firstName"`  LastName string `json:"lastName"`}func getEmployees(w http.ResponseWriter, ...

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