You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/README.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,33 @@ func main() {
158
158
159
159
When you need to convert entire applications or re-use `net/http` middleware chains, rely on the [adaptor middleware](https://docs.gofiber.io/next/middleware/adaptor/). It converts handlers and middlewares in both directions and even lets you mount a Fiber app in a `net/http` server.
160
160
161
+
### Express-style handlers
162
+
163
+
Fiber also adapts Express-style callbacks that operate on the lightweight `fiber.Req` and `fiber.Res` helper interfaces. This lets you port middleware and route handlers from Express-inspired codebases while keeping Fiber's router features:
164
+
165
+
```go
166
+
// Request/response handlers (2-argument)
167
+
app.Get("/", func(req fiber.Req, res fiber.Res) error {
168
+
return res.SendString("Hello from Express-style handlers!")
169
+
})
170
+
171
+
// Middleware with an error-returning next callback (3-argument)
172
+
app.Use(func(req fiber.Req, res fiber.Res, next func() error) error {
173
+
if req.IP() == "192.168.1.254" {
174
+
return res.SendStatus(fiber.StatusForbidden)
175
+
}
176
+
returnnext()
177
+
})
178
+
179
+
// Middleware with a no-arg next callback (3-argument)
180
+
app.Use(func(req fiber.Req, res fiber.Res, next func()) {
181
+
if req.Get("X-Skip") == "true" {
182
+
return// stop the chain without calling next
183
+
}
184
+
next()
185
+
})
186
+
```
187
+
161
188
> **Note:** Adapted `net/http` handlers continue to operate with the standard-library semantics. They don't get access to `fiber.Ctx` features and incur the overhead of the compatibility layer, so native `fiber.Handler` callbacks still provide the best performance.
0 commit comments