Response rendering

As mentioned in Chapter 1, Understanding HTTP, Go, and Echo, the primary purpose of a web application is to take in a request, and render a response to the caller. Fortunately for us, Echo has a multitude of ways we can render responses back to callers. The Echo Context has the following helpers that can be used to render responses, so that you as a developer will not need to serialize the response data yourself:

HTML(code int, html string) error
HTMLBlob(code int, b []byte) error
String(code int, s string) error
JSON(code int, i interface{}) error
JSONPretty(code int, i interface{}, indent string) error
JSONBlob(code int, b []byte) error
JSONP(code int, callback string, i interface{}) error
JSONPBlob(code int, callback ...

Get Echo Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.