Skip to main content
The App type represents your Fiber application and provides methods for routing, configuration, and server lifecycle management.

Creating an App

New

Creates a new Fiber application instance.
func New(config ...Config) *App
config
Config
Optional configuration for the app. See fiber.mdx for all config options.
*App
*App
Returns a new Fiber application instance.
Example
// Default config
app := fiber.New()

// With custom config
app := fiber.New(fiber.Config{
    CaseSensitive: true,
    StrictRouting: true,
    ServerHeader:  "Fiber",
})

NewWithCustomCtx

Creates a new App with a custom context factory function.
func NewWithCustomCtx(fn func(app *App) CustomCtx, config ...Config) *App
fn
func(app *App) CustomCtx
Factory function that creates custom context instances.
config
Config
Optional configuration for the app.
*App
*App
Returns a new Fiber application with custom context support.
Example
type CustomCtx struct {
    fiber.DefaultCtx
}

app := fiber.NewWithCustomCtx(func(app *fiber.App) fiber.CustomCtx {
    return &CustomCtx{
        DefaultCtx: *fiber.NewDefaultCtx(app),
    }
})

Routing Methods

HTTP Method Handlers

Register routes for specific HTTP methods.
func (app *App) Get(path string, handlers ...Handler) Router
func (app *App) Head(path string, handlers ...Handler) Router
func (app *App) Post(path string, handlers ...Handler) Router
func (app *App) Put(path string, handlers ...Handler) Router
func (app *App) Delete(path string, handlers ...Handler) Router
func (app *App) Connect(path string, handlers ...Handler) Router
func (app *App) Options(path string, handlers ...Handler) Router
func (app *App) Trace(path string, handlers ...Handler) Router
func (app *App) Patch(path string, handlers ...Handler) Router
path
string
The route path pattern.
handlers
...Handler
One or more handler functions.
Router
Router
Returns the Router instance for chaining.
Example
app.Get("/", func(c fiber.Ctx) error {
    return c.SendString("GET request")
})

app.Post("/user", func(c fiber.Ctx) error {
    return c.SendString("POST request")
})

Use

Register middleware or mount sub-applications.
func (app *App) Use(args ...any) Router
args
...any
Can be middleware handlers, path prefix, or sub-applications.
Router
Router
Returns the Router instance for chaining.
Example
// Global middleware
app.Use(logger.New())

// Prefixed middleware
app.Use("/api", authMiddleware)

// Mount sub-app
micro := fiber.New()
app.Use("/micro", micro)

Group

Create a route group with a common prefix.
func (app *App) Group(prefix string, handlers ...any) Router
prefix
string
The prefix for all routes in the group.
handlers
...any
Optional middleware handlers for the group.
Router
Router
Returns the group Router instance.
Example
api := app.Group("/api", authMiddleware)

v1 := api.Group("/v1")
v1.Get("/users", getUsers)     // /api/v1/users
v1.Post("/users", createUser)  // /api/v1/users

Route

Define routes with a common prefix using a callback function.
func (app *App) Route(prefix string, fn func(router Router), name ...string) Router
prefix
string
The prefix for all routes defined in the callback.
fn
func(router Router)
Callback function that receives the router.
name
string
Optional name prefix for routes.
Router
Router
Returns the Router instance.
Example
app.Route("/test", func(api fiber.Router) {
    api.Get("/foo", handler).Name("foo") // /test/foo (name: test.foo)
    api.Get("/bar", handler).Name("bar") // /test/bar (name: test.bar)
}, "test.")

RouteChain

Create a chainable route for handling multiple HTTP methods.
func (app *App) RouteChain(path string) Register
path
string
The route path.
Register
Register
Returns a Register interface for chaining method handlers.
Example
app.RouteChain("/api").
    Get(func(c fiber.Ctx) error {
        return c.SendString("GET /api")
    }).
    Post(func(c fiber.Ctx) error {
        return c.SendString("POST /api")
    })

Route Information

Stack

Returns the raw router stack.
func (app *App) Stack() [][]*Route
[][]*Route
[][]*Route
Returns a 2D array of routes organized by HTTP method.
Example
data, _ := json.MarshalIndent(app.Stack(), "", "  ")
fmt.Println(string(data))

GetRoutes

Retrieve all registered routes.
func (app *App) GetRoutes(filterUseOption ...bool) []Route
filterUseOption
bool
When true, filters out routes registered by middleware.
[]Route
[]Route
Returns a slice of all routes.
Example
routes := app.GetRoutes(true)
for _, route := range routes {
    fmt.Printf("%s %s\n", route.Method, route.Path)
}

GetRoute

Retrieve a route by name.
func (app *App) GetRoute(name string) Route
name
string
The route name.
Route
Route
Returns the named route.
Example
app.Get("/", handler).Name("index")
route := app.GetRoute("index")
fmt.Println(route.Path) // "/"

Name

Assign a name to the last created route.
func (app *App) Name(name string) Router
name
string
The name to assign to the route.
Router
Router
Returns the Router instance for chaining.
Example
app.Get("/users/:id", handler).Name("user.show")

HandlersCount

Returns the number of registered handlers.
func (app *App) HandlersCount() uint32
uint32
uint32
Returns the total handler count.

MountPath

Returns the mount path of the application.
func (app *App) MountPath() string
string
string
Returns the mount path or empty string if not mounted.
Example
subApp := fiber.New()
app.Use("/api", subApp)
fmt.Println(subApp.MountPath()) // "/api"

Configuration & State

Config

Returns the app configuration.
func (app *App) Config() Config
Config
Config
Returns a copy of the app configuration.

Handler

Returns the fasthttp request handler.
func (app *App) Handler() fasthttp.RequestHandler
fasthttp.RequestHandler
fasthttp.RequestHandler
Returns the handler compatible with fasthttp server.

ErrorHandler

Executes the configured error handler.
func (app *App) ErrorHandler(ctx Ctx, err error) error
ctx
Ctx
The request context.
err
error
The error to handle.
error
error
Returns an error if the handler fails.

Server Lifecycle

Listen

Start the server on the specified address.
func (app *App) Listen(addr string, config ...ListenConfig) error
addr
string
The address to listen on (e.g., “:3000”).
config
ListenConfig
Optional listen configuration.
error
error
Returns an error if the server fails to start.
Example
if err := app.Listen(":3000"); err != nil {
    log.Fatal(err)
}

Shutdown

Gracefully shutdown the server.
func (app *App) Shutdown() error
error
error
Returns an error if shutdown fails.

Test

Test the app with a simulated HTTP request.
func (app *App) Test(req *http.Request, config ...TestConfig) (*http.Response, error)
req
*http.Request
The HTTP request to test.
config
TestConfig
Optional test configuration (timeout, etc.).
*http.Response
*http.Response
Returns the HTTP response.
error
error
Returns an error if the test fails.
Example
req := httptest.NewRequest("GET", "/", nil)
resp, err := app.Test(req)
if err != nil {
    log.Fatal(err)
}

Hooks

Hooks

Returns the hooks manager.
func (app *App) Hooks() *Hooks
*Hooks
*Hooks
Returns the hooks manager instance.
Example
app.Hooks().OnListen(func(data fiber.ListenData) error {
    fmt.Printf("Listening on %s:%s\n", data.Host, data.Port)
    return nil
})

Advanced

RegisterCustomBinder

Register a custom binder for request body parsing.
func (app *App) RegisterCustomBinder(binder CustomBinder)
binder
CustomBinder
The custom binder implementation.

RegisterCustomConstraint

Register a custom route constraint.
func (app *App) RegisterCustomConstraint(constraint CustomConstraint)
constraint
CustomConstraint
The custom constraint implementation.

RebuildTree

Rebuild the routing tree (for dynamic route registration).
func (app *App) RebuildTree() *App
*App
*App
Returns the app instance for chaining.
This method is not thread-safe and should only be used in development mode.

RemoveRoute

Remove a route by path.
func (app *App) RemoveRoute(path string, methods ...string)
path
string
The route path to remove.
methods
...string
Optional HTTP methods. If omitted, removes for all methods.

GetString

Returns a string respecting the Immutable setting.
func (app *App) GetString(s string) string
s
string
The input string.
string
string
Returns the string (cloned if Immutable is enabled).

GetBytes

Returns a byte slice respecting the Immutable setting.
func (app *App) GetBytes(b []byte) []byte
b
[]byte
The input byte slice.
[]byte
[]byte
Returns the byte slice (cloned if Immutable is enabled).

Build docs developers (and LLMs) love