-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
Feature Proposal Description
Since we now have support for non-Fiber net/http handlers for app.Get() and other methods in #3769, we should add an express-style handler as an option as well.
Since we have added fiber.Req and fiber.Res interfaces in #3533, we can use these as the expected req and res parameters Express uses in their handlers.
Alignment with Express API
Express uses the following handler styles:
app.get("/", (req, res) => {
// Do something with req and res
});app.get("/", (req, res, next) => {
// Do something with req and res
next();
});If we support these in Fiber, we can get closer to the Express API while still allowing the older fiber.Ctx style handlers.
HTTP RFC Standards Compliance
N/A
API Stability
Express' API doesn't change these handler signatures, and supporting these handler should not make any changes to the current router logic, aside from adding a new adaptor and type case.
Feature Examples
package main
import (
"log"
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New()
app.Use(func(req fiber.Req, res fiber.Res, next func() error) {
if req.IP() == "192.168.1.254" {
return res.Drop()
}
return next()
})
app.Get("/", func(req fiber.Req, res fiber.Res) error {
return res.SendString("Hello World!")
})
log.Fatal(app.Listen(":3000"))
}Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have searched for existing issues that describe my proposal before opening this one.
- I understand that a proposal that does not meet these guidelines may be closed without explanation.
ReneWerner87
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done