2023-02-25 12:29:07 +03:00
---
slug: /
id: welcome
title: ๐ Welcome
sidebar_position: 1
---
2025-08-26 12:37:19 +02:00
Welcome to Fiber's online API documentation, complete with examples to help you start building web applications right away!
2023-02-25 12:29:07 +03:00
2024-11-13 07:11:09 -05:00
**Fiber ** is an [Express ](https://github.com/expressjs/express )-inspired **web framework ** built on top of [Fasthttp ](https://github.com/valyala/fasthttp ), the **fastest ** HTTP engine for [Go ](https://go.dev/doc/ ). It is designed to facilitate rapid development with **zero memory allocations ** and a strong focus on **performance ** .
2023-02-25 12:29:07 +03:00
2025-08-29 12:34:19 +02:00
These docs cover **Fiber v3 ** .
2023-02-25 12:29:07 +03:00
2025-08-20 00:06:58 -06:00
Looking to practice Fiber concepts hands-on? Check out our [Learning Resources ](./extra/learning-resources ) for interactive challenges and tutorials.
2023-02-25 12:29:07 +03:00
### Installation
2025-08-14 08:15:43 +02:00
First, [download ](https://go.dev/dl/ ) and install Go. Version `1.25` or higher is required.
2023-02-25 12:29:07 +03:00
2025-08-26 12:37:19 +02:00
Install Fiber using the [`go get` ](https://pkg.go.dev/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them ) command:
2023-02-25 12:29:07 +03:00
``` bash
2024-01-08 16:39:59 +01:00
go get github.com/gofiber/fiber/v3
2023-02-25 12:29:07 +03:00
```
### Zero Allocation
2025-08-26 12:37:19 +02:00
Fiber is optimized for **high performance ** , meaning values returned from **fiber.Ctx ** are **not ** immutable by default and **will ** be reused across requests. As a rule of thumb, you should use context values only within the handler and **must not ** keep any references. Once you return from the handler, any values obtained from the context will be reused in future requests. Here is an example:
2023-02-25 12:29:07 +03:00
``` go
2024-01-08 07:31:15 -08:00
func handler ( c fiber . Ctx ) error {
2023-02-25 12:29:07 +03:00
// Variable is only valid within this handler
2025-09-16 22:01:56 +02:00
result := c . Params ( "foo" )
2023-02-25 12:29:07 +03:00
// ...
}
```
2025-08-29 12:34:19 +02:00
If you need to persist such values outside the handler, make copies of their **underlying buffer ** using the [copy ](https://pkg.go.dev/builtin/#copy ) builtin. Here is an example of persisting a string:
2023-02-25 12:29:07 +03:00
``` go
2024-01-08 07:31:15 -08:00
func handler ( c fiber . Ctx ) error {
2023-02-25 12:29:07 +03:00
// Variable is only valid within this handler
result := c . Params ( "foo" )
// Make a copy
buffer := make ( [ ] byte , len ( result ) )
copy ( buffer , result )
2025-09-16 22:01:56 +02:00
resultCopy := string ( buffer )
2024-11-13 07:11:09 -05:00
// Variable is now valid indefinitely
2023-02-25 12:29:07 +03:00
// ...
}
```
2025-08-29 12:34:19 +02:00
Fiber provides `GetString` and `GetBytes` methods on the app that detach values when `Immutable` is enabled and the data isn't already read-only. If it's disabled, use `utils.CopyString` and `utils.CopyBytes` to allocate only when necessary.
2023-02-25 12:29:07 +03:00
``` go
2024-01-08 07:31:15 -08:00
app . Get ( "/:foo" , func ( c fiber . Ctx ) error {
2025-08-26 07:54:15 +02:00
// Detach if necessary when Immutable is enabled
result := c . App ( ) . GetString ( c . Params ( "foo" ) )
2023-02-25 12:29:07 +03:00
2024-07-11 09:21:56 -04:00
// ...
2023-02-25 12:29:07 +03:00
} )
```
2024-11-13 07:11:09 -05:00
Alternatively, you can enable the `Immutable` setting. This makes all values returned from the context immutable, allowing you to persist them anywhere. Note that this comes at the cost of performance.
2023-02-25 12:29:07 +03:00
``` go
app := fiber . New ( fiber . Config {
2024-07-11 09:21:56 -04:00
Immutable : true ,
2023-02-25 12:29:07 +03:00
} )
```
2024-11-13 07:11:09 -05:00
For more information, please refer to [#426 ](https://github.com/gofiber/fiber/issues/426 ), [#185 ](https://github.com/gofiber/fiber/issues/185 ), and [#3012 ](https://github.com/gofiber/fiber/issues/3012 ).
2023-02-25 12:29:07 +03:00
2024-07-11 09:21:56 -04:00
### Hello, World
2023-02-25 12:29:07 +03:00
2025-08-26 12:37:19 +02:00
Here is the simplest **Fiber ** application you can create:
2023-02-25 12:29:07 +03:00
``` go
package main
2024-01-08 16:42:07 +01:00
import "github.com/gofiber/fiber/v3"
2023-02-25 12:29:07 +03:00
func main ( ) {
2024-07-11 09:21:56 -04:00
app := fiber . New ( )
2023-02-25 12:29:07 +03:00
2024-07-11 09:21:56 -04:00
app . Get ( "/" , func ( c fiber . Ctx ) error {
return c . SendString ( "Hello, World!" )
} )
2023-02-25 12:29:07 +03:00
2024-07-11 09:21:56 -04:00
app . Listen ( ":3000" )
2023-02-25 12:29:07 +03:00
}
```
2024-04-23 08:18:19 +02:00
``` bash
2023-02-25 12:29:07 +03:00
go run server.go
```
2024-11-13 07:11:09 -05:00
Browse to `http://localhost:3000` and you should see `Hello, World!` displayed on the page.
2023-02-25 12:29:07 +03:00
2024-11-13 07:11:09 -05:00
### Basic Routing
2023-02-25 12:29:07 +03:00
2025-08-26 12:37:19 +02:00
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.).
2023-02-25 12:29:07 +03:00
Each route can have **multiple handler functions ** that are executed when the route is matched.
2024-11-13 07:11:09 -05:00
Route definitions follow the structure below:
2023-02-25 12:29:07 +03:00
``` go
// Function signature
2024-01-08 07:31:15 -08:00
app . Method ( path string , ... func ( fiber . Ctx ) error )
2023-02-25 12:29:07 +03:00
```
- `app` is an instance of **Fiber **
2025-09-16 22:01:56 +02:00
- `Method` is an [HTTP request method ](./api/app#route-handlers ): `GET` , `PUT` , `POST` , etc.
2023-02-25 12:29:07 +03:00
- `path` is a virtual path on the server
2025-09-16 22:01:56 +02:00
- `func(fiber.Ctx) error` is a callback function containing the [Context ](./api/ctx ) executed when the route is matched
2023-02-25 12:29:07 +03:00
2024-11-13 07:11:09 -05:00
#### Simple Route
2023-02-25 12:29:07 +03:00
``` go
2024-11-13 07:11:09 -05:00
// Respond with "Hello, World!" on root path "/"
2024-01-08 07:31:15 -08:00
app . Get ( "/" , func ( c fiber . Ctx ) error {
2024-07-11 09:21:56 -04:00
return c . SendString ( "Hello, World!" )
2023-02-25 12:29:07 +03:00
} )
```
2024-07-11 09:21:56 -04:00
#### Parameters
2023-02-25 12:29:07 +03:00
``` go
// GET http://localhost:8080/hello%20world
2024-01-08 07:31:15 -08:00
app . Get ( "/:value" , func ( c fiber . Ctx ) error {
2024-07-11 09:21:56 -04:00
return c . SendString ( "value: " + c . Params ( "value" ) )
2024-11-13 07:11:09 -05:00
// => Response: "value: hello world"
2023-02-25 12:29:07 +03:00
} )
```
2024-11-13 07:11:09 -05:00
#### Optional Parameter
2023-02-25 12:29:07 +03:00
``` go
// GET http://localhost:3000/john
2024-01-08 07:31:15 -08:00
app . Get ( "/:name?" , func ( c fiber . Ctx ) error {
2024-07-11 09:21:56 -04:00
if c . Params ( "name" ) != "" {
return c . SendString ( "Hello " + c . Params ( "name" ) )
2024-11-13 07:11:09 -05:00
// => Response: "Hello john"
2024-07-11 09:21:56 -04:00
}
return c . SendString ( "Where is john?" )
2024-11-13 07:11:09 -05:00
// => Response: "Where is john?"
2023-02-25 12:29:07 +03:00
} )
```
2024-07-11 09:21:56 -04:00
#### Wildcards
2023-02-25 12:29:07 +03:00
``` go
// GET http://localhost:3000/api/user/john
2024-01-08 07:31:15 -08:00
app . Get ( "/api/*" , func ( c fiber . Ctx ) error {
2024-07-11 09:21:56 -04:00
return c . SendString ( "API path: " + c . Params ( "*" ) )
2024-11-13 07:11:09 -05:00
// => Response: "API path: user/john"
2023-02-25 12:29:07 +03:00
} )
```
2024-11-13 07:11:09 -05:00
### Static Files
2023-02-25 12:29:07 +03:00
2025-02-10 08:35:56 +01:00
To serve static files such as **images ** , **CSS ** , and **JavaScript ** files, use the [static middleware ](./middleware/static.md ).
2023-02-25 12:29:07 +03:00
Use the following code to serve files in a directory named `./public` :
``` go
2024-11-13 07:11:09 -05:00
package main
import (
"github.com/gofiber/fiber/v3"
2025-02-10 08:35:56 +01:00
"github.com/gofiber/fiber/v3/middleware/static"
2024-11-13 07:11:09 -05:00
)
2023-02-25 12:29:07 +03:00
2024-11-13 07:11:09 -05:00
func main ( ) {
app := fiber . New ( )
2023-02-25 12:29:07 +03:00
2025-02-10 08:35:56 +01:00
app . Use ( "/" , static . New ( "./public" ) )
2024-11-13 07:11:09 -05:00
app . Listen ( ":3000" )
}
2023-02-25 12:29:07 +03:00
```
2024-11-13 07:11:09 -05:00
Now, you can access the files in the `./public` directory via your browser:
2023-02-25 12:29:07 +03:00
``` bash
2023-07-22 16:42:48 +01:00
http://localhost:3000/hello.html
http://localhost:3000/js/jquery.js
http://localhost:3000/css/style.css
2023-02-25 12:29:07 +03:00
```