Logo

GoFiber

HTTP Routers & Frameworks

GitHub

Details

Category: HTTP Routers & Frameworks

Github: https://github.com/gofiber/fiber

Website: https://gofiber.io/

Published: May 2025

Tool Description

Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.


⚠️ Attention

Fiber v3 is currently in beta and under active development. While it offers exciting new features, please note that it may not be stable for production use. We recommend sticking to the latest stable release (v2.x) for mission-critical applications. If you choose to use v3, be prepared for potential bugs and breaking changes. Always check the official documentation and release notes for updates and proceed with caution. Happy coding! πŸš€


βš™οΈ Installation

Fiber requires Go version 1.23 or higher to run. If you need to install or upgrade Go, visit the official Go download page. To start setting up your project, create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal:

go mod init github.com/your/repo

To learn more about Go modules and how they work, you can check out the Using Go Modules blog post.

After setting up your project, you can install Fiber with the go get command:

go get -u github.com/gofiber/fiber/v3

This command fetches the Fiber package and adds it to your project's dependencies, allowing you to start building your web applications with Fiber.

⚑️ Quickstart

Getting started with Fiber is easy. Here's a basic example to create a simple web server that responds with "Hello, World πŸ‘‹!" on the root path. This example demonstrates initializing a new Fiber app, setting up a route, and starting the server.

package main

import (
    "log"

    "github.com/gofiber/fiber/v3"
)

func main() {
    // Initialize a new Fiber app
    app := fiber.New()

    // Define a route for the GET method on the root path '/'
    app.Get("/", func(c fiber.Ctx) error {
        // Send a string response to the client
        return c.SendString("Hello, World πŸ‘‹!")
    })

    // Start the server on port 3000
    log.Fatal(app.Listen(":3000"))
}

This simple server is easy to set up and run. It introduces the core concepts of Fiber: app initialization, route definition, and starting the server. Just run this Go program, and visit http://localhost:3000 in your browser to see the message.

Zero Allocation

Fiber is optimized for high-performance, meaning values returned from fiber.Ctx are not immutable by default and will be re-used across requests. As a rule of thumb, you must only use context values within the handler and must not keep any references. Once you return from the handler, any values obtained from the context will be re-used in future requests. Visit our documentation to learn more.

πŸ€– Benchmarks

These tests are performed by TechEmpower. If you want to see all the results, please visit our Wiki.

🎯 Features


πŸ’‘ Philosophy

New gophers that make the switch from Node.js to Go are dealing with a learning curve before they can start building their web applications or microservices. Fiber, as a web framework, was created with the idea of minimalism and follows the UNIX way, so that new gophers can quickly enter the world of Go with a warm and trusted welcome.

Fiber is inspired by Express, the most popular web framework on the Internet. We combined the ease of Express and raw performance of Go. If you have ever implemented a web application in Node.js (using Express or similar), then many methods and principles will seem very common to you.

We listen to our users in issues, Discord channel and all over the Internet to create a fast, flexible and friendly Go web framework for any task, deadline and developer skill! Just like Express does in the JavaScript world.

⚠️ Limitations


πŸ‘€ Examples

Listed below are some of the common examples. If you want to see more code examples, please visit our Recipes repository or visit our hosted API documentation.

πŸ“– Basic Routing

package main

import (
    "fmt"
    "log"

    "github.com/gofiber/fiber/v3"
)

func main() {
    app := fiber.New()

    // GET /api/register
    app.Get("/api/*", func(c fiber.Ctx) error {
        msg := fmt.Sprintf("βœ‹ %s", c.Params("*"))
        return c.SendString(msg) // => βœ‹ register
    })

    // GET /flights/LAX-SFO
    app.Get("/flights/:from-:to", func(c fiber.Ctx) error {
        msg := fmt.Sprintf("πŸ’Έ From: %s, To: %s", c.Params("from"), c.Params("to"))
        return c.SendString(msg) // => πŸ’Έ From: LAX, To: SFO
    })

    // GET /dictionary.txt
    app.Get("/:file.:ext", func(c fiber.Ctx) error {
        msg := fmt.Sprintf("πŸ“ƒ %s.%s", c.Params("file"), c.Params("ext"))
        return c.SendString(msg) // => πŸ“ƒ dictionary.txt
    })

    // GET /john/75
    app.Get("/:name/:age/:gender?", func(c fiber.Ctx) error {
        msg := fmt.Sprintf("πŸ‘΄ %s is %s years old", c.Params("name"), c.Params("age"))
        return c.SendString(msg) // => πŸ‘΄ john is 75 years old
    })

    // GET /john
    app.Get("/:name", func(c fiber.Ctx) error {
        msg := fmt.Sprintf("Hello, %s πŸ‘‹!", c.Params("name"))
        return c.SendString(msg) // => Hello john πŸ‘‹!
    })

    log.Fatal(app.Listen(":3000"))
}

πŸ“– Route Naming

package main

import (
    "encoding/json"
    "fmt"
    "log"

    "github.com/gofiber/fiber/v3"
)

func main() {
    app := fiber.New()

    app.Get("/api/*", func(c fiber.Ctx) error {
        msg := fmt.Sprintf("βœ‹ %s", c.Params("*"))
        return c.SendString(msg) // => βœ‹ register
    }).Name("api")

    route := app.GetRoute("api")

    data, _ := json.MarshalIndent(route, "", "  ")
    fmt.Println(string(data))
    // Prints:
    // {
    //    "method": "GET",
    //    "name": "api",
    //    "path": "/api/*",
    //    "params": [
    //      "*1"
    //    ]
    // }

    log.Fatal(app.Listen(":3000"))
}

πŸ“– Serving Static Files

package main

import (
    "log"

    "github.com/gofiber/fiber/v3"
    "github.com/gofiber/fiber/v3/middleware/static"
)

func main() {
    app := fiber.New()

    // Serve static files from the "./public" directory
    app.Get("/*", static.New("./public"))
    // => http://localhost:3000/js/script.js
    // => http://localhost:3000/css/style.css

    app.Get("/prefix*", static.New("./public"))
    // => http://localhost:3000/prefix/js/script.js
    // => http://localhost:3000/prefix/css/style.css

    // Serve a single file for any unmatched routes
    app.Get("*", static.New("./public/index.html"))
    // => http://localhost:3000/any/path/shows/index.html

    log.Fatal(app.Listen(":3000"))
}

πŸ“– Middleware & Next

package main

import (
    "fmt"
    "log"

    "github.com/gofiber/fiber/v3"
)

func main() {
    app := fiber.New()

    // Middleware that matches any route
    app.Use(func(c fiber.Ctx) error {
        fmt.Println("πŸ₯‡ First handler")
        return c.Next()
    })

    // Middleware that matches all routes starting with /api
    app.Use("/api", func(c fiber.Ctx) error {
        fmt.Println("πŸ₯ˆ Second handler")
        return c.Next()
    })

    // GET /api/list
    app.Get("/api/list", func(c fiber.Ctx) error {
        fmt.Println("πŸ₯‰ Last handler")
        return c.SendString("Hello, World πŸ‘‹!")
    })

    log.Fatal(app.Listen(":3000"))
}


🧬 Internal Middleware

Here is a list of middleware that are included within the Fiber framework.


🧬 External Middleware

List of externally hosted middleware modules and maintained by the Fiber team.


πŸ•ΆοΈ Awesome List

For more articles, middlewares, examples, or tools, check our awesome list.

πŸ‘ Contribute

If you want to say Thank You and/or support the active development of Fiber:


πŸ’» Development

To ensure your contributions are ready for a Pull Request, please use the following Makefile commands. These tools help maintain code quality and consistency.


Run these commands to ensure your code adheres to project standards and best practices.

β˜• Supporters

Fiber is an open-source project that runs on donations to pay the bills, e.g., our domain name, GitBook, Netlify, and serverless hosting. If you want to support Fiber, you can β˜• buy a coffee here.


πŸ’» Code Contributors

Code Contributors

⭐️ Stargazers

Stargazers over time

🧾 License

Copyright (c) 2019-present Fenny and Contributors. Fiber is free and open-source software licensed under the MIT License. Official logo was created by Vic ShΓ³stak and distributed under Creative Commons license (CC BY-SA 4.0 International).

View more HTTP Routers & Frameworks Go Tools

View HTTP Routers & Frameworks tools