Echo handlers
One of the first things that stands out when using Echo handlers is the echo.Context interface. We no longer receive the standard http.ResponseWriter and *http.Request parameters in our handler functions. Instead, we receive echo.Context, which, under the hood, uses ResponseWriter and Request but provides us with a lot more power. The context allows us to return JSON responses directly based on data structures or handle the incoming requests’ data more conveniently by using tools such as data binding or validation. Let’s see this in action:
e.GET("/hello/:name", func(c echo.Context) {
name := c.Param("name")
return c.JSON(http.StatusOK, map[string]string{"hello": name})
})
Here, we are registering another GET endpoint, but this time, we are getting some data from the URL path. We need something for our API to pass the resource IDs. With c.Param, we can get the parameter by name and use it directly. But we also...