Documentation 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.
Core type definitions and configuration options for the Fiber web framework.
Core Types
Handler
The signature for all route handlers and middleware.
type Handler = func(Ctx) error
Handlers receive a Ctx (context) and return an error. If a handler returns an error, Fiber will invoke the error handler.
func myHandler(c fiber.Ctx) error {
return c.SendString("Hello, World!")
}
app.Get("/", myHandler)
Map
A shortcut type for map[string]any, useful for JSON responses.
app.Get("/api/user", func(c fiber.Ctx) error {
return c.JSON(fiber.Map{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
})
})
Error
Represents an HTTP error with a status code and message.
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
}
NewError
Create a new Fiber error.
func NewError(code int, message ...string) *Error
Returns a new Error instance.
app.Get("/admin", func(c fiber.Ctx) error {
if !isAdmin(c) {
return fiber.NewError(fiber.StatusForbidden, "Admin access required")
}
return c.SendString("Admin panel")
})
ErrorHandler
The signature for custom error handlers.
type ErrorHandler = func(Ctx, error) error
app := fiber.New(fiber.Config{
ErrorHandler: func(c fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
return c.Status(code).JSON(fiber.Map{
"error": err.Error(),
})
},
})
Configuration
Config
Configuration options for creating a new Fiber app.
type Config struct {
// Server settings
AppName string
ServerHeader string
// Routing
CaseSensitive bool
StrictRouting bool
// Limits
BodyLimit int
Concurrency int
// And many more options...
}
Key Configuration Fields
Application name used in logs and Server header.
Sets the Server HTTP header value.
When enabled, /Foo and /foo are different routes.
When enabled, /foo and /foo/ are different routes.
BodyLimit
int
default:"4 * 1024 * 1024"
Maximum request body size in bytes (4MB default).
Maximum duration for reading the full request including body.
Maximum duration before timing out writes of the response.
Maximum amount of time to wait for the next request when keep-alive is enabled.
Maximum number of concurrent connections.
Disable keep-alive connections.
DisableDefaultContentType
When true, omits default Content-Type header.
When true, omits default Date header.
Disable header name normalization.
When enabled, all values returned by context methods are immutable.
Decode encoded characters in the route path.
Template engine for rendering views.
Global layout for template rendering.
Pass c.Locals() values to template engine.
JSONEncoder
utils.JSONMarshal
default:"json.Marshal"
Custom JSON encoder function.
JSONDecoder
utils.JSONUnmarshal
default:"json.Unmarshal"
Custom JSON decoder function.
XMLEncoder
utils.XMLMarshal
default:"xml.Marshal"
Custom XML encoder function.
XMLDecoder
utils.XMLUnmarshal
default:"xml.Unmarshal"
Custom XML decoder function.
ErrorHandler
ErrorHandler
default:"DefaultErrorHandler"
Custom error handler function.
Validate IP addresses before returning them.
Trust proxy headers for IP, protocol, and host.
Header name for proxy IP address.
Aggressively reduce memory usage at the cost of higher CPU usage.
Reject all non-GET requests.
app := fiber.New(fiber.Config{
AppName: "My Application",
ServerHeader: "Fiber",
BodyLimit: 10 * 1024 * 1024, // 10MB
CaseSensitive: true,
StrictRouting: true,
Immutable: true,
ErrorHandler: func(c fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
return c.Status(code).SendString(err.Error())
},
})
ListenConfig
Configuration for server listening.
type ListenConfig struct {
DisableStartupMessage bool
EnablePrefork bool
CertFile string
CertKeyFile string
CertClientFile string
BeforeServeFunc func(app *App) error
}
Disable the startup banner.
Enable prefork mode (multiple processes).
Path to TLS certificate file.
Path to TLS private key file.
Path to client certificate for mTLS.
BeforeServeFunc
func(app *App) error
default:"nil"
Callback executed before serving.
app.Listen(":3000", fiber.ListenConfig{
EnablePrefork: true,
CertFile: "./cert.pem",
CertKeyFile: "./key.pem",
})
TestConfig
Configuration for testing with app.Test().
type TestConfig struct {
Timeout time.Duration
FailOnTimeout bool
}
Timeout
time.Duration
default:"1s"
Maximum duration for the test request.
Whether to fail the test on timeout.
Constants
Fiber exports many constants for HTTP methods, status codes, headers, and MIME types. See the constants.mdx page for a complete reference.
Version
The current Fiber version.
Interfaces
Views
Interface for template engines.
type Views interface {
Load() error
Render(io.Writer, string, interface{}, ...string) error
}
Router
Interface for routing operations.
type Router interface {
Use(args ...any) Router
Get(path string, handlers ...Handler) Router
Post(path string, handlers ...Handler) Router
Put(path string, handlers ...Handler) Router
Delete(path string, handlers ...Handler) Router
Patch(path string, handlers ...Handler) Router
// ... and more HTTP methods
Group(prefix string, handlers ...any) Router
Route(prefix string, fn func(Router), name ...string) Router
Name(name string) Router
}
CustomCtx
Extended context interface for custom implementations.
type CustomCtx interface {
Ctx
Reset(fctx *fasthttp.RequestCtx)
// Internal methods...
}