Fiber
Express-inspired web framework for Go built on Fasthttp with zero-allocation routing and parsing.
Official Documentation ↗v2. Check the official docs for the latest API surface.Installation
go get github.com/gofiber/fiber/v2Methods
No methods match this filter.
Express-inspired web framework for Go built on Fasthttp with zero-allocation routing and parsing.
Overview
Fiber brings Express-style ergonomics to Go on top of the Fasthttp engine: app verbs register routes, chained middleware handles cross-cutting concerns, and the request context exposes params, queries, bodies, and JSON responses with terse calls.
The framework ships common middleware, logging, recover, caching, compression, and supports returning errors from handlers for centralized failure handling. Its context and router are tuned for low allocations at high request rates.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
fiber.New / Listen— Creates the application over Fasthttp and starts the listener.app.Get / app.Post— Registers route handlers; paths support :param and *wildcard segments.fiber.Ctx methods— Request inspection and response helpers, including binding bodies into structs.app.Use / middleware— Mounts middleware for all or prefix-matched routes; handlers return errors to the chain.
Usage Notes
- Return fiber.NewError with status codes instead of writing error responses inline.
- Copy strings out of Ctx before goroutines or background work, contexts are recycled.
- Check middleware compatibility first if you depend on net/http-oriented packages.
Common Pitfalls
- Ctx values accessed after the handler returns point into recycled memory.
- Streaming request bodies need BodyStream and careful handling, not the buffered c.Body().
- Strict HTTP conformance cases, some header edge cases, can differ from net/http behavior.
FAQ
- How is Fiber different from net/http frameworks?
- Fiber rides Fasthttp, not net/http, trading strict HTTP conformance for throughput and a per-request context object. Middleware written for net/http does not drop in, and edge-case HTTP behavior differs; validate that against your requirements before adopting.
- Why do handlers return error?
- The error propagates to Fiber central error handling, which converts it into a response through the configured ErrorHandler. fiber.NewError carries a status code for direct control, keeping handlers free of response plumbing.
- Is the request context safe to keep?
- No. Values read from Ctx are only guaranteed during the handler; Fasthttp recycles objects after the response. Copy anything you need for later, strings through c.Params or copy the bytes explicitly.
Report a problem with this API docOpens a pre-filled issue on GitHub.