Reader small image

You're reading from  Echo Quick Start Guide

Product typeBook
Published inMay 2018
PublisherPackt
ISBN-139781789139433
Edition1st Edition
Tools
Right arrow
Author (1)
Ben Huson
Ben Huson
author image
Ben Huson

John Huson is an Echo developer
Read more about Ben Huson

Right arrow

Request binding

Within the context interface in the Echo framework, there is a method called Bind, which will perform request payload binding. The following is the definition of the function:

    // Bind binds the request body into provided type `i`. The default binder
    // does it based on Content-Type header.
    Bind(i interface{}) error

In essence, the Context.Bind function takes the payload and Content-Type header from the HTTP request, and converts it into any structure defined by the passed in i interface{} function parameter. This is a very handy feature of the web application framework as it removes a lot of the coding required by the developer to interpret the request payload themselves. Instead of having to perform deserialization of the HTTP request body yourself, Echo will perform this for you. The following is an example handler that uses the Bind function call...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Echo Quick Start Guide
Published in: May 2018Publisher: PacktISBN-13: 9781789139433

Author (1)

author image
Ben Huson

John Huson is an Echo developer
Read more about Ben Huson