docs/guide/faster-fiber.md
Fiber defaults to the standard encoding/json for stability and reliability. If you need more speed, consider these libraries:
package main
import "github.com/gofiber/fiber/v3"
import "github.com/goccy/go-json"
func main() {
app := fiber.New(fiber.Config{
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
})
// ...
}
regex() ConstraintsFiber route patterns still do not support general regex routes, but you can swap
the compiler used by regex() parameter constraints through
Config.RegexHandler. This lets you try
high-performance engines such as
coregex on the matching path.
RegexHandlerSet RegexHandler to the compile function you want Fiber to use for regex()
constraints.
package main
import (
"github.com/coregx/coregex"
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New(fiber.Config{
RegexHandler: coregex.MustCompile,
})
app.Get("/api/:id<regex(\\d+)>", func(c fiber.Ctx) error {
return c.SendString("ID: " + c.Params("id"))
})
}
You can also set it explicitly to the standard library default:
package main
import (
"regexp"
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New(fiber.Config{
RegexHandler: regexp.MustCompile,
})
_ = app
}
RegexHandler only affects regex() parameter constraintsMustCompile-style semanticsRegexHandler more than once per route while parsing raw and
normalized route patterns during registration