What it is
Fiber is a Go web framework built on fasthttp rather than net/http, with an API deliberately modelled on Express.js. It targets maximum raw throughput and low memory allocation.
Fiber's routing, middleware and context API closely mirror Express. It includes middleware for CORS, compression, caching, rate limiting, sessions and WebSockets, and supports route grouping, mounting sub-apps and static file serving.
Installation
go get github.com/gofiber/fiber/v2Getting started
The smallest useful thing you can do with it, and what each part means.
package main
import "github.com/gofiber/fiber/v2"
func main() {
app := fiber.New(fiber.Config{
AppName: "books",
ReadTimeout: 5 * time.Second,
ErrorHandler: customErrors,
})
app.Get("/books/:id", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"id": c.Params("id")})
})
app.Listen(":8080")
}type Filter struct {
Author string `query:"author"`
Limit int `query:"limit"`
}
app.Get("/books", func(c *fiber.Ctx) error {
var f Filter
if err := c.QueryParser(&f); err != nil {
return fiber.NewError(fiber.StatusBadRequest, "bad query")
}
if f.Limit == 0 || f.Limit > 100 {
f.Limit = 20
}
return c.JSON(store.Search(f.Author, f.Limit))
})Advanced usage
Where the library earns its place over a simpler alternative.
app.Post("/jobs", func(c *fiber.Ctx) error {
// fiber.Ctx is pooled and reused after the handler returns.
// Copy anything you need before starting background work.
body := make([]byte, len(c.Body()))
copy(body, c.Body())
id := utils.CopyString(c.Params("id"))
go func() {
process(id, body) // safe: operating on copies
}()
return c.SendStatus(fiber.StatusAccepted)
})Errors and fixes
The failures you are most likely to hit, and what actually resolves them.
- Corrupted or empty strings inside a goroutine
- You captured a value backed by a pooled buffer. Use utils.CopyString for strings and copy() for byte slices before leaving the handler.
- Standard net/http middleware does not compile
- Fiber uses fasthttp, which has different types. Use the adaptor package (github.com/gofiber/fiber/v2/middleware/adaptor) or find a Fiber-native equivalent.
Best practices
- Copy any value taken from c before using it in a goroutine or storing it — the underlying buffers are reused.
- Set ReadTimeout and WriteTimeout in fiber.Config; the defaults are unlimited.
- Check that middleware you need exists for Fiber — net/http middleware is not compatible without an adaptor.
- Prefer Fiber only when you have measured that net/http is genuinely your bottleneck.
Background
Why it exists, and what it was reacting to.
Fiber was created by Fenny in 2020 to give Node.js developers moving to Go a familiar API. Its choice of fasthttp over net/http buys significant benchmark performance at the cost of incompatibility with the standard library's middleware ecosystem.
