Rendering
As mentioned previously, the job of a web application or an API is to create an HTTP response message, given an HTTP request message. Echo has a really nice facility to help us render responses from our handlers and middleware functions. echo.Context
has methods which perform all of the heavy hitting for rendering responses back to the caller. As seen in prior examples, there is a JSON
method on the Echo Context which allows for rendering of a JSON payload back to the caller. The following is a list of supported rendering capabilities within Echo:
HTML: Render an HTML response:
HTMLBlob: Render a preformed HTML response
JSON: Render a JSON response, converting the variable into JSON based on the
struct
tags of the variable:JSONBlob: Render a preformed JSON response
JSONPretty: Render a pretty JSON response
JSONP: Render a JSONP response based on the
struct
tags of the variable
XML: Render an XML response based on the
struct
tags of the variable:XMLBlob: Render a preformed XML string
XMLPretty...