docs/intro.md
Welcome to Fiber's online API documentation, complete with examples to help you start building web applications right away!
Fiber is an Express-inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. It is designed to facilitate rapid development with zero memory allocations and a strong focus on performance. Fiber also ships batteries included: built-in middleware, officially maintained integrations, storage drivers, and template engines cover most production needs (see Explore the Ecosystem below).
These docs cover Fiber v3.
:::tip Coming from Fiber v2? See What's New in v3 for the migration guide and the CLI migration tool. :::
First, download and install Go. Version 1.25 or higher is required.
Install Fiber using the go get command:
go get github.com/gofiber/fiber/v3
Create a file named server.go with the simplest Fiber application you can write:
package main
import (
"log"
"github.com/gofiber/fiber/v3"
)
func main() {
app := fiber.New()
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("Hello, World!")
})
log.Fatal(app.Listen(":3000"))
}
Run it:
go run server.go
Browse to http://localhost:3000 and you should see Hello, World! displayed on the page.
Routing determines how an application responds to a client request at a particular endpoint, a combination of path and HTTP request method (GET, PUT, POST, etc.).
Route definitions follow the structure below:
// Function signature
func (app *App) Get(path string, handler any, handlers ...any) Router
app is an instance of FiberGet is an HTTP request method; Post, Put, Delete, and the other methods work the same waypath is a virtual path on the serverhandler is a function executed when the route is matched; the canonical form is func(fiber.Ctx) error, and a route can register multiple handlersFor an interactive breakdown of every part of a route definition, see the anatomy of a route.
A simple route and a route with a parameter:
// Respond with "Hello, World!" on root path "/"
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("Hello, World!")
})
// GET http://localhost:3000/hello%20world
app.Get("/:value", func(c fiber.Ctx) error {
return c.SendString("value: " + c.Params("value"))
// => Response: "value: hello world"
})
See the routing guide for optional parameters, wildcards, constraints, route groups, and the full list of supported handler types.
To serve static files such as images, CSS, and JavaScript files, register the static middleware:
import "github.com/gofiber/fiber/v3/middleware/static"
app.Use("/", static.New("./public"))
Files in the ./public directory are now reachable in the browser, for example at http://localhost:3000/css/style.css.
Middleware runs before or after your handlers and takes care of cross-cutting concerns. Registering one is a single app.Use call; here is the logger middleware printing every request:
import "github.com/gofiber/fiber/v3/middleware/logger"
app.Use(logger.New())
Middleware for logging, CORS, rate limiting, sessions, compression, panic recovery, and much more ships with Fiber itself; the ecosystem section below shows where to find it all.
:::caution Fiber is optimized for high performance, so values returned from fiber.Ctx are not immutable by default and will be reused across requests. Use context values only within the handler, and do not keep any references after the handler returns. :::
If you need to persist a context value beyond the handler, make a copy of its underlying buffer using the copy builtin:
func handler(c fiber.Ctx) error {
// Variable is only valid within this handler
result := c.Params("foo")
// Make a copy
buffer := make([]byte, len(result))
copy(buffer, result)
resultCopy := string(buffer)
// Variable is now valid indefinitely
// ...
}
Alternatively, you can enable the Immutable setting. This makes all values returned from the context immutable, allowing you to persist them anywhere, at the cost of some performance:
app := fiber.New(fiber.Config{
Immutable: true,
})
For details, see Immutable in the configuration reference and the GetString and GetBytes helpers.
Fiber is more than the core module. When your application grows, these officially maintained building blocks are one import away:
Ready to go deeper? These guides and references cover the everyday tasks:
fiber.Newapp.TestStuck or have questions? Join the Discord server or check the FAQ. Fiber is developed in the open on GitHub; issues, discussions, and contributions are welcome.