TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/gofiber/fiber/llms.txt
Use this file to discover all available pages before exploring further.
adaptor package converts between Fiber and net/http, letting you reuse handlers, middleware, and requests across both frameworks.
Features
- Convert
net/httphandlers and middleware to Fiber handlers - Convert Fiber handlers to
net/httphandlers - Convert a Fiber context (
fiber.Ctx) into anhttp.Request - Copy values stored in a
context.Contextonto afasthttp.RequestCtx
When Fiber is executed from a
net/http server through FiberHandler, FiberHandlerFunc,
or FiberApp, the adaptor enforces the app’s configured BodyLimit. The app’s BodyLimit defaults to 4 MiB if a non-positive value is provided during configuration. Requests exceeding the active limit receive 413 Request Entity Too Large.API Reference
| Name | Signature | Description |
|---|---|---|
HTTPHandler | HTTPHandler(h http.Handler) fiber.Handler | Converts http.Handler to fiber.Handler |
HTTPHandlerWithContext | HTTPHandlerWithContext(h http.Handler) fiber.Handler | Converts http.Handler to fiber.Handler, propagating Fiber’s local context |
HTTPHandlerFunc | HTTPHandlerFunc(h http.HandlerFunc) fiber.Handler | Converts http.HandlerFunc to fiber.Handler |
HTTPMiddleware | HTTPMiddleware(mw func(http.Handler) http.Handler) fiber.Handler | Converts http.Handler middleware to fiber.Handler middleware |
FiberHandler | FiberHandler(h fiber.Handler) http.Handler | Converts fiber.Handler to http.Handler |
FiberHandlerFunc | FiberHandlerFunc(h fiber.Handler) http.HandlerFunc | Converts fiber.Handler to http.HandlerFunc |
FiberApp | FiberApp(app *fiber.App) http.HandlerFunc | Converts an entire Fiber app to a http.HandlerFunc |
ConvertRequest | ConvertRequest(c fiber.Ctx, forServer bool) (*http.Request, error) | Converts fiber.Ctx into a http.Request |
LocalContextFromHTTPRequest | LocalContextFromHTTPRequest(r *http.Request) (context.Context, bool) | Extracts the propagated context.Context from an adapted http.Request |
CopyContextToFiberContext | CopyContextToFiberContext(context any, requestContext *fasthttp.RequestCtx) | Copies context.Context to fasthttp.RequestCtx |
Usage Examples
Using net/http handlers in Fiber
Run standard net/http handlers inside Fiber. Fiber can auto-adapt them, or you can
explicitly convert them when you want to cache or share the converted handler.
Using net/http middleware with Fiber
Middleware written for net/http can run inside Fiber:
Using Fiber handlers in net/http
You can use Fiber handlers from net/http:
Running a full Fiber app inside net/http
You can wrap a full Fiber app inside net/http:
Converting fiber.Ctx to *http.Request
Create an *http.Request from a fiber.Ctx. The forServer parameter determines how
server-oriented fields are populated:
- Use
forServer = truewhen the converted request will be passed into anet/httphandler - Use
forServer = falsewhen creating a request for client-side use
Passing Fiber user context into net/http
This example shows a realistic flow: a Fiber middleware sets a request-scoped context.Context on the Fiber context, then an adapted net/http handler retrieves it.
Common Use Cases
Integrating Third-Party net/http Middleware
Many Go packages provide net/http middleware. Use HTTPMiddleware to integrate them:
Migrating from net/http to Fiber
Gradually migrate by running your existing net/http handlers in Fiber:
Using Fiber in Existing net/http Applications
Integrate Fiber into an existing net/http application: