1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-10 00:28:23 +02:00
echo/website/content/recipes/middleware.md
Vishal Rana b6547dde66 recipe & website in the main repo
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-20 11:30:53 -07:00

800 B

+++ title = "Middleware Recipe" description = "Middleware recipe / example for Echo" [menu.side] name = "Middleware" parent = "recipes" weight = 3 +++

Middleware Recipe

How to write a custom middleware?

  • Middleware to collect request count, statuses and uptime.
  • Middleware to write custom Server header to the response.

Server

server.go

{{< embed "middleware/server.go" >}}

Response

Headers

Content-Length:122
Content-Type:application/json; charset=utf-8
Date:Thu, 14 Apr 2016 20:31:46 GMT
Server:Echo/2.0

Body

{
  "uptime": "2016-04-14T13:28:48.486548936-07:00",
  "requestCount": 5,
  "statuses": {
    "200": 4,
    "404": 1
  }
}

Maintainers

[Source Code]({{< source "middleware" >}})