Skip to content

Commit 0e2c515

Browse files
Add docs from gofiber/fiber@4e98910
1 parent 2b67c6b commit 0e2c515

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
id: responsetime
3+
---
4+
5+
# ResponseTime
6+
7+
Response time middleware for [Fiber](https://github.com/gofiber/fiber) that measures the time spent handling a request and exposes it via a response header.
8+
9+
## Signatures
10+
11+
```go
12+
func New(config ...Config) fiber.Handler
13+
```
14+
15+
## Examples
16+
17+
Import the package:
18+
19+
```go
20+
import (
21+
"github.com/gofiber/fiber/v3"
22+
"github.com/gofiber/fiber/v3/middleware/responsetime"
23+
)
24+
```
25+
26+
### Default config
27+
28+
```go
29+
app.Use(responsetime.New())
30+
```
31+
32+
### Custom header
33+
34+
```go
35+
app.Use(responsetime.New(responsetime.Config{
36+
Header: "X-Elapsed",
37+
}))
38+
```
39+
40+
### Skip logic
41+
42+
```go
43+
app.Use(responsetime.New(responsetime.Config{
44+
Next: func(c fiber.Ctx) bool {
45+
return c.Path() == "/healthz"
46+
},
47+
}))
48+
```
49+
50+
## Config
51+
52+
| Property | Type | Description | Default |
53+
| :------- | :--- | :---------- | :------ |
54+
| Next | `func(c fiber.Ctx) bool` | Defines a function to skip this middleware when it returns `true`. | `nil` |
55+
| Header | `string` | Header key used to store the measured response time. If left empty, the default header is used. | `"X-Response-Time"` |

docs/core/whats_new.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,12 @@ Cache keys are now redacted in logs and error messages by default, and a `Disabl
12441244
The deprecated `Store` and `Key` options have been removed in v3. Use `Storage` and `KeyGenerator` instead.
12451245
:::
12461246

1247+
### ResponseTime
1248+
1249+
A new response time middleware measures how long each request takes to process and adds the duration to the response headers.
1250+
By default it writes the elapsed time to `X-Response-Time`, and you can change the header name. A `Next` hook lets you skip
1251+
endpoints such as health checks.
1252+
12471253
### CORS
12481254

12491255
We've made some changes to the CORS middleware to improve its functionality and flexibility. Here's what's new:

0 commit comments

Comments
 (0)