Skip to main content

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.
Example
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.
type Map map[string]any
Example
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
code
int
The HTTP status code.
message
string
Optional error message.
*Error
*Error
Returns a new Error instance.
Example
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
Example
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

AppName
string
default:""
Application name used in logs and Server header.
ServerHeader
string
default:""
Sets the Server HTTP header value.
CaseSensitive
bool
default:"false"
When enabled, /Foo and /foo are different routes.
StrictRouting
bool
default:"false"
When enabled, /foo and /foo/ are different routes.
BodyLimit
int
default:"4 * 1024 * 1024"
Maximum request body size in bytes (4MB default).
ReadTimeout
time.Duration
default:"0"
Maximum duration for reading the full request including body.
WriteTimeout
time.Duration
default:"0"
Maximum duration before timing out writes of the response.
IdleTimeout
time.Duration
default:"0"
Maximum amount of time to wait for the next request when keep-alive is enabled.
Concurrency
int
default:"256 * 1024"
Maximum number of concurrent connections.
DisableKeepalive
bool
default:"false"
Disable keep-alive connections.
DisableDefaultContentType
bool
default:"false"
When true, omits default Content-Type header.
DisableDefaultDate
bool
default:"false"
When true, omits default Date header.
DisableHeaderNormalizing
bool
default:"false"
Disable header name normalization.
Immutable
bool
default:"false"
When enabled, all values returned by context methods are immutable.
UnescapePath
bool
default:"false"
Decode encoded characters in the route path.
Views
Views
default:"nil"
Template engine for rendering views.
ViewsLayout
string
default:""
Global layout for template rendering.
PassLocalsToViews
bool
default:"false"
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.
EnableIPValidation
bool
default:"false"
Validate IP addresses before returning them.
TrustProxy
bool
default:"false"
Trust proxy headers for IP, protocol, and host.
ProxyHeader
string
default:""
Header name for proxy IP address.
ReduceMemoryUsage
bool
default:"false"
Aggressively reduce memory usage at the cost of higher CPU usage.
GETOnly
bool
default:"false"
Reject all non-GET requests.
Example
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
}
DisableStartupMessage
bool
default:"false"
Disable the startup banner.
EnablePrefork
bool
default:"false"
Enable prefork mode (multiple processes).
CertFile
string
default:""
Path to TLS certificate file.
CertKeyFile
string
default:""
Path to TLS private key file.
CertClientFile
string
default:""
Path to client certificate for mTLS.
BeforeServeFunc
func(app *App) error
default:"nil"
Callback executed before serving.
Example
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.
FailOnTimeout
bool
default:"true"
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.
const Version = "3.1.0"

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...
}