Creating your first REST client
Today, most applications that communicate with servers use RESTful services. Based on our needs, we consume these services through JavaScript, jQuery, or through a REST client.
In this recipe, we will write a REST client using the https://gopkg.in/resty.v1
package, which itself is inspired by the Ruby rest client to consume the RESTful services.
Getting ready…
Run http-rest-get.go
, which we created in one of our previous recipes, in a separate terminal, executing the following command:
$ go run http-rest-get.go
Note
See the Creating your first HTTP GET method recipe.
Verify whether the /employees
service is running locally on port 8080
by executing the following command:
$ curl -X GET http://localhost:8080/employees
This should return the following response:
[{"id":"1","firstName":"Foo","lastName":"Bar"},{"id":"2","firstName":"Baz","lastName":"Qux"}]
How to do it…
- Install the
github.com/gorilla/mux
andgopkg.in/resty.v1
packages using thego get
command, as follows:
$...