Skip to content

Echo Context: Request vs Echo Context

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Echo Context: Request vs Echo Context. We cover key concepts, practical examples, and best practices.

Echo framework context -- Understand how Echo's context wraps http.Request and how to access request properties correctly.

The Problem

Echo's c echo.Context provides convenience methods but hides the underlying http.Request. Always use c.Request() to get the underlying *http.Request.

Wrong

func handler(c echo.Context) error {
    method := c.Method // Not available!
    return c.String(200, "ok")
}

Output:

// Compile error:
// c.Method undefined
func handler(c echo.Context) error {
    req := c.Request()
    c.Logger().Infof("%s %s", req.Method, req.URL.Path)
    return c.String(200, "ok")
}

Output:

$ curl http://localhost:8080/hello
// Server log: GET /hello
// Response: ok

Prevention

  • Use c.Request() to access the underlying *http.Request
  • Use c.Response() for response headers and status
  • Echo provides shortcuts: c.Path(), c.Method(), c.QueryParam()
  • Use c.FormValue("key") for form/query params
  • Use c.Bind(&obj) for request body binding

Common Mistakes with echo context

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world GO code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

**How do I access query parameters in Echo?**

Use c.QueryParam("name") for single or c.QueryParams()["name"] for multiple.

How do I get path parameters in Echo?

Use c.Param("id") for route parameters like /users/:id.

How do I set response headers?

Use c.Response().Header().Set("Key", "Value").


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tutorials help Go developers build production-ready software used by millions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro