import ( "github.com/alexanderchen1989/go-json-rest/rest" "net/http" ) func helloWorld(w rest.ResponseWriter, r *rest.Request) { w.WriteHeader(http.StatusOK) w.WriteJson(map[string]string{"message": "Hello, world!"}) }
import ( "github.com/alexanderchen1989/go-json-rest/rest" ) func getUsers(w rest.ResponseWriter, r *rest.Request) { users := []User{{Name: "John", Age: 21}, {Name: "Lucy", Age: 25}} w.WriteJson(users) }This example shows how to use the ResponseWriter to return a JSON array of user objects to the client. In summary, go-json-rest.rest is a package library that provides tools for building RESTful APIs in Go. The ResponseWriter is a feature of this library that helps developers write responses to HTTP requests.