Handlers

At this point, it is known that routes map target paths to handlers, but what are handlers? Handlers are the meat of web application development. A handler is primarily where the application converts input into output. As mentioned before, net/http defines a handler as an implementation of the http.Handler interface, implementing the ServeHTTP method with the following signature:

func (f Handler) ServeHTTP(w ResponseWriter, r *Request)

Echo has detoured from this model by creating its own interface for an echo.HandlerFunc, defined by the following signature:

type HandlerFunc func(Context) error

Following our example code, the following is an initial attempt at creating a handler for the /login resource of our application. This code ...

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.