Skip to main content
Version: Next

ResponseTime

Response time middleware for Fiber that measures the time spent handling a request and exposes it via a response header.

Signatures

func New(config ...Config) fiber.Handler

Examples

Import the package:

import (
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/responsetime"
)

Default config

app.Use(responsetime.New())

Custom header

app.Use(responsetime.New(responsetime.Config{
Header: "X-Elapsed",
}))

Skip logic

app.Use(responsetime.New(responsetime.Config{
Next: func(c fiber.Ctx) bool {
return c.Path() == "/healthz"
},
}))

Config

PropertyTypeDescriptionDefault
Nextfunc(c fiber.Ctx) boolDefines a function to skip this middleware when it returns true.nil
HeaderstringHeader key used to store the measured response time. If left empty, the default header is used."X-Response-Time"