{"id":13416621,"url":"https://github.com/gofiber/fiber","last_synced_at":"2026-01-31T17:14:46.264Z","repository":{"id":37319799,"uuid":"234231371","full_name":"gofiber/fiber","owner":"gofiber","description":"⚡️ Express inspired web framework written in Go","archived":false,"fork":false,"pushed_at":"2025-05-03T05:47:00.000Z","size":228330,"stargazers_count":36297,"open_issues_count":124,"forks_count":1779,"subscribers_count":283,"default_branch":"main","last_synced_at":"2025-05-05T11:11:49.587Z","etag":null,"topics":["express","expressjs","fast","fiber","flexible","framework","friendly","go","golang","hacktoberfest","hacktoberfest2020","nodejs","performance","rest-api","web"],"latest_commit_sha":null,"homepage":"https://gofiber.io","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gofiber.png","metadata":{"files":{"readme":".github/README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["gofiber"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"custom":"https://github.com/sponsors/gofiber"}},"created_at":"2020-01-16T03:59:20.000Z","updated_at":"2025-05-05T10:03:15.000Z","dependencies_parsed_at":"2024-01-12T13:33:22.682Z","dependency_job_id":"633da716-3c48-4e59-9ad8-0867022e6d91","html_url":"https://github.com/gofiber/fiber","commit_stats":{"total_commits":3059,"total_committers":385,"mean_commits":7.945454545454545,"dds":0.718208564890487,"last_synced_commit":"109ccdd4adbaf604c12186c41a2060f0eaf4424a"},"previous_names":[],"tags_count":128,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofiber%2Ffiber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofiber%2Ffiber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofiber%2Ffiber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofiber%2Ffiber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gofiber","download_url":"https://codeload.github.com/gofiber/fiber/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252486917,"owners_count":21755835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","expressjs","fast","fiber","flexible","framework","friendly","go","golang","hacktoberfest","hacktoberfest2020","nodejs","performance","rest-api","web"],"created_at":"2024-07-30T22:00:17.148Z","updated_at":"2026-01-31T17:14:46.258Z","avatar_url":"https://github.com/gofiber.png","language":"Go","readme":"\u003ch1 align=\"center\"\u003e\n  \u003ca href=\"https://gofiber.io\"\u003e\n    \u003cpicture\u003e\n      \u003csource height=\"125\" media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/gofiber/docs/master/static/img/logo-dark.svg\"\u003e\n      \u003cimg height=\"125\" alt=\"Fiber\" src=\"https://raw.githubusercontent.com/gofiber/docs/master/static/img/logo.svg\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://pkg.go.dev/github.com/gofiber/fiber/v3#pkg-overview\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/%F0%9F%93%9A%20godoc-pkg-00ACD7.svg?color=00ACD7\u0026style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://goreportcard.com/report/github.com/gofiber/fiber/v3\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/%F0%9F%93%9D%20goreport-A%2B-75C46B?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/gofiber/fiber\" \u003e\n   \u003cimg alt=\"Codecov\" src=\"https://img.shields.io/codecov/c/github/gofiber/fiber?token=3Cr92CwaPQ\u0026style=flat-square\u0026logo=codecov\u0026label=codecov\"\u003e\n \u003c/a\u003e\n  \u003ca href=\"https://github.com/gofiber/fiber/actions?query=workflow%3ATest\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/gofiber/fiber/test.yml?branch=main\u0026label=%F0%9F%A7%AA%20tests\u0026style=flat-square\u0026color=75C46B\"\u003e\n  \u003c/a\u003e\n    \u003ca href=\"https://docs.gofiber.io\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/%F0%9F%92%A1%20fiber-docs-00ACD7.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://gofiber.io/discord\"\u003e\n    \u003cimg src=\"https://img.shields.io/discord/704680098577514527?style=flat-square\u0026label=%F0%9F%92%AC%20discord\u0026color=00ACD7\"\u003e\n  \u003c/a\u003e\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n  \u003cem\u003e\u003cb\u003eFiber\u003c/b\u003e is an \u003ca href=\"https://github.com/expressjs/express\"\u003eExpress\u003c/a\u003e inspired \u003cb\u003eweb framework\u003c/b\u003e built on top of \u003ca href=\"https://github.com/valyala/fasthttp\"\u003eFasthttp\u003c/a\u003e, the \u003cb\u003efastest\u003c/b\u003e HTTP engine for \u003ca href=\"https://go.dev/doc/\"\u003eGo\u003c/a\u003e. Designed to \u003cb\u003eease\u003c/b\u003e things up for \u003cb\u003efast\u003c/b\u003e development with \u003ca href=\"https://docs.gofiber.io/#zero-allocation\"\u003e\u003cb\u003ezero memory allocation\u003c/b\u003e\u003c/a\u003e and \u003cb\u003eperformance\u003c/b\u003e in mind.\u003c/em\u003e\n\u003c/p\u003e\n\n---\n\n## ⚙️ Installation\n\nFiber requires **Go version `1.25` or higher** to run. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/). 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:\n\n```bash\ngo mod init github.com/your/repo\n```\n\nTo learn more about Go modules and how they work, you can check out the [Using Go Modules](https://go.dev/blog/using-go-modules) blog post.\n\nAfter setting up your project, you can install Fiber with the `go get` command:\n\n```bash\ngo get -u github.com/gofiber/fiber/v3\n```\n\nThis command fetches the Fiber package and adds it to your project's dependencies, allowing you to start building your web applications with Fiber.\n\n## ⚡️ Quickstart\n\nGetting 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.\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    // Initialize a new Fiber app\n    app := fiber.New()\n\n    // Define a route for the GET method on the root path '/'\n    app.Get(\"/\", func(c fiber.Ctx) error {\n        // Send a string response to the client\n        return c.SendString(\"Hello, World 👋!\")\n    })\n\n    // Start the server on port 3000\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\nThis 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.\n\n## Zero Allocation\n\nFiber 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](https://docs.gofiber.io/#zero-allocation) to learn more.\n\n## 🤖 Benchmarks\n\nThese tests are performed by [TechEmpower](https://www.techempower.com/benchmarks/#section=data-r19\u0026hw=ph\u0026test=plaintext). If you want to see all the results, please visit our [Wiki](https://docs.gofiber.io/extra/benchmarks).\n\n\u003cp float=\"left\" align=\"middle\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/gofiber/docs/master/static/img/plaintext.png\" width=\"49%\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/gofiber/docs/master/static/img/json.png\" width=\"49%\"\u003e\n\u003c/p\u003e\n\n## 🎯 Features\n\n- Robust [Routing](https://docs.gofiber.io/guide/routing)\n- Serve [Static Files](https://docs.gofiber.io/api/app#static)\n- Extreme [Performance](https://docs.gofiber.io/extra/benchmarks)\n- [Low Memory](https://docs.gofiber.io/extra/benchmarks) footprint\n- [API Endpoints](https://docs.gofiber.io/api/ctx)\n- [Middleware](https://docs.gofiber.io/category/-middleware) \u0026 [Next](https://docs.gofiber.io/api/ctx#next) support\n- [Rapid](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programming\n- [Template Engines](https://github.com/gofiber/template)\n- [WebSocket Support](https://github.com/gofiber/contrib/tree/main/websocket)\n- [Socket.io Support](https://github.com/gofiber/contrib/tree/main/socketio)\n- [Server-Sent Events](https://github.com/gofiber/recipes/tree/master/sse)\n- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)\n- And much more, [explore Fiber](https://docs.gofiber.io/)\n\n## 💡 Philosophy\n\nNew gophers that make the switch from [Node.js](https://nodejs.org/en/about/) to [Go](https://go.dev/doc/) 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.\n\nFiber 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.\n\nWe **listen** to our users in [issues](https://github.com/gofiber/fiber/issues), Discord [channel](https://gofiber.io/discord) _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.\n\n## ⚠️ Limitations\n\n- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber v3 has been tested with Go version 1.24 or higher.\n- Fiber automatically adapts common `net/http` handler shapes when you register them on the router, and you can still use the [adaptor middleware](https://docs.gofiber.io/next/middleware/adaptor/) when you need to bridge entire apps or `net/http` middleware.\n\n### net/http compatibility\n\nFiber can run side by side with the standard library. The router accepts existing `net/http` handlers directly and even works with native `fasthttp.RequestHandler` callbacks, so you can plug in legacy endpoints without wrapping them manually:\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"net/http\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    httpHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n        if _, err := w.Write([]byte(\"served by net/http\")); err != nil {\n            panic(err)\n        }\n    })\n\n    app := fiber.New()\n    app.Get(\"/\", httpHandler)\n\n    // Start the server on port 3000\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\nWhen you need to convert entire applications or re-use `net/http` middleware chains, rely on the [adaptor middleware](https://docs.gofiber.io/next/middleware/adaptor/). It converts handlers and middlewares in both directions and even lets you mount a Fiber app in a `net/http` server.\n\n### Express-style handlers\n\nFiber also adapts Express-style callbacks that operate on the lightweight `fiber.Req` and `fiber.Res` helper interfaces. This lets you port middleware and route handlers from Express-inspired codebases while keeping Fiber's router features:\n\n```go\n// Request/response handlers (2-argument)\napp.Get(\"/\", func(req fiber.Req, res fiber.Res) error {\n    return res.SendString(\"Hello from Express-style handlers!\")\n})\n\n// Middleware with an error-returning next callback (3-argument)\napp.Use(func(req fiber.Req, res fiber.Res, next func() error) error {\n    if req.IP() == \"192.168.1.254\" {\n        return res.SendStatus(fiber.StatusForbidden)\n    }\n    return next()\n})\n\n// Middleware with a no-arg next callback (3-argument)\napp.Use(func(req fiber.Req, res fiber.Res, next func()) {\n    if req.Get(\"X-Skip\") == \"true\" {\n        return // stop the chain without calling next\n    }\n    next()\n})\n```\n\n\u003e **Note:** Adapted `net/http` handlers continue to operate with the standard-library semantics. They don't get access to `fiber.Ctx` features and incur the overhead of the compatibility layer, so native `fiber.Handler` callbacks still provide the best performance.\n\n## 👀 Examples\n\nListed below are some of the common examples. If you want to see more code examples, please visit our [Recipes repository](https://github.com/gofiber/recipes) or visit our hosted [API documentation](https://docs.gofiber.io).\n\n### 📖 [**Basic Routing**](https://docs.gofiber.io/#basic-routing)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // GET /api/register\n    app.Get(\"/api/*\", func(c fiber.Ctx) error {\n        msg := fmt.Sprintf(\"✋ %s\", c.Params(\"*\"))\n        return c.SendString(msg) // =\u003e ✋ register\n    })\n\n    // GET /flights/LAX-SFO\n    app.Get(\"/flights/:from-:to\", func(c fiber.Ctx) error {\n        msg := fmt.Sprintf(\"💸 From: %s, To: %s\", c.Params(\"from\"), c.Params(\"to\"))\n        return c.SendString(msg) // =\u003e 💸 From: LAX, To: SFO\n    })\n\n    // GET /dictionary.txt\n    app.Get(\"/:file.:ext\", func(c fiber.Ctx) error {\n        msg := fmt.Sprintf(\"📃 %s.%s\", c.Params(\"file\"), c.Params(\"ext\"))\n        return c.SendString(msg) // =\u003e 📃 dictionary.txt\n    })\n\n    // GET /john/75\n    app.Get(\"/:name/:age/:gender?\", func(c fiber.Ctx) error {\n        msg := fmt.Sprintf(\"👴 %s is %s years old\", c.Params(\"name\"), c.Params(\"age\"))\n        return c.SendString(msg) // =\u003e 👴 john is 75 years old\n    })\n\n    // GET /john\n    app.Get(\"/:name\", func(c fiber.Ctx) error {\n        msg := fmt.Sprintf(\"Hello, %s 👋!\", c.Params(\"name\"))\n        return c.SendString(msg) // =\u003e Hello john 👋!\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n#### 📖 [**Route Naming**](https://docs.gofiber.io/api/app#name)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    app.Get(\"/api/*\", func(c fiber.Ctx) error {\n        msg := fmt.Sprintf(\"✋ %s\", c.Params(\"*\"))\n        return c.SendString(msg) // =\u003e ✋ register\n    }).Name(\"api\")\n\n    route := app.GetRoute(\"api\")\n\n    data, _ := json.MarshalIndent(route, \"\", \"  \")\n    fmt.Println(string(data))\n    // Prints:\n    // {\n    //    \"method\": \"GET\",\n    //    \"name\": \"api\",\n    //    \"path\": \"/api/*\",\n    //    \"params\": [\n    //      \"*1\"\n    //    ]\n    // }\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n#### 📖 [**Serving Static Files**](https://docs.gofiber.io/api/app#static)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/gofiber/fiber/v3/middleware/static\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Serve static files from the \"./public\" directory\n    app.Get(\"/*\", static.New(\"./public\"))\n    // =\u003e http://localhost:3000/js/script.js\n    // =\u003e http://localhost:3000/css/style.css\n\n    app.Get(\"/prefix*\", static.New(\"./public\"))\n    // =\u003e http://localhost:3000/prefix/js/script.js\n    // =\u003e http://localhost:3000/prefix/css/style.css\n\n    // Serve a single file for any unmatched routes\n    app.Get(\"*\", static.New(\"./public/index.html\"))\n    // =\u003e http://localhost:3000/any/path/shows/index.html\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n#### 📖 [**Middleware \u0026 Next**](https://docs.gofiber.io/api/ctx#next)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Middleware that matches any route\n    app.Use(func(c fiber.Ctx) error {\n        fmt.Println(\"🥇 First handler\")\n        return c.Next()\n    })\n\n    // Middleware that matches all routes starting with /api\n    app.Use(\"/api\", func(c fiber.Ctx) error {\n        fmt.Println(\"🥈 Second handler\")\n        return c.Next()\n    })\n\n    // GET /api/list\n    app.Get(\"/api/list\", func(c fiber.Ctx) error {\n        fmt.Println(\"🥉 Last handler\")\n        return c.SendString(\"Hello, World 👋!\")\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003e📚 Show more code examples\u003c/summary\u003e\n\n### Views Engines\n\n📖 [Config](https://docs.gofiber.io/api/fiber#config)\n📖 [Engines](https://github.com/gofiber/template)\n📖 [Render](https://docs.gofiber.io/api/ctx#render)\n\nFiber defaults to the [html/template](https://pkg.go.dev/html/template/) when no view engine is set.\n\nIf you want to execute partials or use a different engine like [amber](https://github.com/eknkc/amber), [handlebars](https://github.com/aymerick/raymond), [mustache](https://github.com/cbroglie/mustache), or [pug](https://github.com/Joker/jade), etc., check out our [Template](https://github.com/gofiber/template) package that supports multiple view engines.\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/gofiber/template/pug\"\n)\n\nfunc main() {\n    // Initialize a new Fiber app with Pug template engine\n    app := fiber.New(fiber.Config{\n        Views: pug.New(\"./views\", \".pug\"),\n    })\n\n    // Define a route that renders the \"home.pug\" template\n    app.Get(\"/\", func(c fiber.Ctx) error {\n        return c.Render(\"home\", fiber.Map{\n            \"title\": \"Homepage\",\n            \"year\":  1999,\n        })\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### Grouping Routes into Chains\n\n📖 [Group](https://docs.gofiber.io/api/app#group)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc middleware(c fiber.Ctx) error {\n    log.Println(\"Middleware executed\")\n    return c.Next()\n}\n\nfunc handler(c fiber.Ctx) error {\n    return c.SendString(\"Handler response\")\n}\n\nfunc main() {\n    app := fiber.New()\n\n    // Root API group with middleware\n    api := app.Group(\"/api\", middleware) // /api\n\n    // API v1 routes\n    v1 := api.Group(\"/v1\", middleware) // /api/v1\n    v1.Get(\"/list\", handler)           // /api/v1/list\n    v1.Get(\"/user\", handler)           // /api/v1/user\n\n    // API v2 routes\n    v2 := api.Group(\"/v2\", middleware) // /api/v2\n    v2.Get(\"/list\", handler)           // /api/v2/list\n    v2.Get(\"/user\", handler)           // /api/v2/user\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### Middleware Logger\n\n📖 [Logger](https://docs.gofiber.io/api/middleware/logger)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/gofiber/fiber/v3/middleware/logger\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Use Logger middleware\n    app.Use(logger.New())\n\n    // Define routes\n    app.Get(\"/\", func(c fiber.Ctx) error {\n        return c.SendString(\"Hello, Logger!\")\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### Cross-Origin Resource Sharing (CORS)\n\n📖 [CORS](https://docs.gofiber.io/api/middleware/cors)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/gofiber/fiber/v3/middleware/cors\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Use CORS middleware with default settings\n    app.Use(cors.New())\n\n    // Define routes\n    app.Get(\"/\", func(c fiber.Ctx) error {\n        return c.SendString(\"CORS enabled!\")\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\nCheck CORS by passing any domain in `Origin` header:\n\n```bash\ncurl -H \"Origin: http://example.com\" --verbose http://localhost:3000\n```\n\n### Custom 404 Response\n\n📖 [HTTP Methods](https://docs.gofiber.io/api/ctx#status)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Define routes\n    app.Get(\"/\", static.New(\"./public\"))\n\n    app.Get(\"/demo\", func(c fiber.Ctx) error {\n        return c.SendString(\"This is a demo page!\")\n    })\n\n    app.Post(\"/register\", func(c fiber.Ctx) error {\n        return c.SendString(\"Registration successful!\")\n    })\n\n    // Middleware to handle 404 Not Found\n    app.Use(func(c fiber.Ctx) error {\n        return c.SendStatus(fiber.StatusNotFound) // =\u003e 404 \"Not Found\"\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### JSON Response\n\n📖 [JSON](https://docs.gofiber.io/api/ctx#json)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\ntype User struct {\n    Name string `json:\"name\"`\n    Age  int    `json:\"age\"`\n}\n\nfunc main() {\n    app := fiber.New()\n\n    // Route that returns a JSON object\n    app.Get(\"/user\", func(c fiber.Ctx) error {\n        return c.JSON(\u0026User{\"John\", 20})\n        // =\u003e {\"name\":\"John\", \"age\":20}\n    })\n\n    // Route that returns a JSON map\n    app.Get(\"/json\", func(c fiber.Ctx) error {\n        return c.JSON(fiber.Map{\n            \"success\": true,\n            \"message\": \"Hi John!\",\n        })\n        // =\u003e {\"success\":true, \"message\":\"Hi John!\"}\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### WebSocket Upgrade\n\n📖 [Websocket](https://github.com/gofiber/websocket)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/gofiber/fiber/v3/middleware/websocket\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // WebSocket route\n    app.Get(\"/ws\", websocket.New(func(c *websocket.Conn) {\n        defer c.Close()\n        for {\n            // Read message from client\n            mt, msg, err := c.ReadMessage()\n            if err != nil {\n                log.Println(\"read:\", err)\n                break\n            }\n            log.Printf(\"recv: %s\", msg)\n\n            // Write message back to client\n            err = c.WriteMessage(mt, msg)\n            if err != nil {\n                log.Println(\"write:\", err)\n                break\n            }\n        }\n    }))\n\n    log.Fatal(app.Listen(\":3000\"))\n    // Connect via WebSocket at ws://localhost:3000/ws\n}\n```\n\n### Server-Sent Events\n\n📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"log\"\n    \"time\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/valyala/fasthttp\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Server-Sent Events route\n    app.Get(\"/sse\", func(c fiber.Ctx) error {\n        c.Set(\"Content-Type\", \"text/event-stream\")\n        c.Set(\"Cache-Control\", \"no-cache\")\n        c.Set(\"Connection\", \"keep-alive\")\n        c.Set(\"Transfer-Encoding\", \"chunked\")\n\n        c.Context().SetBodyStreamWriter(func(w *bufio.Writer) {\n            var i int\n            for {\n                i++\n                msg := fmt.Sprintf(\"%d - the time is %v\", i, time.Now())\n                fmt.Fprintf(w, \"data: Message: %s\\n\\n\", msg)\n                fmt.Println(msg)\n\n                w.Flush()\n                time.Sleep(5 * time.Second)\n            }\n        })\n\n        return nil\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### Recover Middleware\n\n📖 [Recover](https://docs.gofiber.io/api/middleware/recover)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n    \"github.com/gofiber/fiber/v3/middleware/recover\"\n)\n\nfunc main() {\n    app := fiber.New()\n\n    // Use Recover middleware to handle panics gracefully\n    app.Use(recover.New())\n\n    // Route that intentionally panics\n    app.Get(\"/\", func(c fiber.Ctx) error {\n        panic(\"normally this would crash your app\")\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n### Using Trusted Proxy\n\n📖 [Config](https://docs.gofiber.io/api/fiber#config)\n\n```go title=\"Example\"\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/gofiber/fiber/v3\"\n)\n\nfunc main() {\n    app := fiber.New(fiber.Config{\n        // Configure trusted proxies - WARNING: Only trust proxies you control\n        // Using TrustProxy: true with unrestricted IPs can lead to IP spoofing\n        TrustProxy: true,\n        TrustProxyConfig: fiber.TrustProxyConfig{\n            Proxies: []string{\"10.0.0.0/8\", \"172.16.0.0/12\"}, // Example: Internal network ranges only\n        },\n        ProxyHeader: fiber.HeaderXForwardedFor,\n    })\n\n    // Define routes\n    app.Get(\"/\", func(c fiber.Ctx) error {\n        return c.SendString(\"Trusted Proxy Configured!\")\n    })\n\n    log.Fatal(app.Listen(\":3000\"))\n}\n```\n\n\u003c/details\u003e\n\n## 🧬 Internal Middleware\n\nHere is a list of middleware that are included within the Fiber framework.\n\n| Middleware                                                                           | Description                                                                                                                                                             |\n|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [adaptor](https://github.com/gofiber/fiber/tree/main/middleware/adaptor)             | Converter for net/http handlers to/from Fiber request handlers.                                                                                                         |\n| [basicauth](https://github.com/gofiber/fiber/tree/main/middleware/basicauth)         | Provides HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials.                            |\n| [cache](https://github.com/gofiber/fiber/tree/main/middleware/cache)                 | Intercept and cache HTTP responses.                                                                                                                                     |\n| [compress](https://github.com/gofiber/fiber/tree/main/middleware/compress)           | Compression middleware for Fiber, with support for `deflate`, `gzip`, `brotli` and `zstd`.                                                                             |\n| [cors](https://github.com/gofiber/fiber/tree/main/middleware/cors)                   | Enable cross-origin resource sharing (CORS) with various options.                                                                                                       |\n| [csrf](https://github.com/gofiber/fiber/tree/main/middleware/csrf)                   | Protect from CSRF exploits.                                                                                                                                             |\n| [earlydata](https://github.com/gofiber/fiber/tree/main/middleware/earlydata)         | Adds support for TLS 1.3's early data (\"0-RTT\") feature.                                                                                                                |\n| [encryptcookie](https://github.com/gofiber/fiber/tree/main/middleware/encryptcookie) | Encrypt middleware which encrypts cookie values.                                                                                                                        |\n| [envvar](https://github.com/gofiber/fiber/tree/main/middleware/envvar)               | Expose environment variables with providing an optional config.                                                                                                         |\n| [etag](https://github.com/gofiber/fiber/tree/main/middleware/etag)                   | Allows for caches to be more efficient and save bandwidth, as a web server does not need to resend a full response if the content has not changed.                      |\n| [expvar](https://github.com/gofiber/fiber/tree/main/middleware/expvar)               | Serves via its HTTP server runtime exposed variables in the JSON format.                                                                                                 |\n| [favicon](https://github.com/gofiber/fiber/tree/main/middleware/favicon)             | Ignore favicon from logs or serve from memory if a file path is provided.                                                                                               |\n| [healthcheck](https://github.com/gofiber/fiber/tree/main/middleware/healthcheck)     | Liveness and Readiness probes for Fiber.                                                                                                                                |\n| [helmet](https://github.com/gofiber/fiber/tree/main/middleware/helmet)               | Helps secure your apps by setting various HTTP headers.                                                                                                                 |\n| [idempotency](https://github.com/gofiber/fiber/tree/main/middleware/idempotency)     | Allows for fault-tolerant APIs where duplicate requests do not erroneously cause the same action performed multiple times on the server-side.                           |\n| [keyauth](https://github.com/gofiber/fiber/tree/main/middleware/keyauth)             | Adds support for key based authentication.                                                                                                                              |\n| [limiter](https://github.com/gofiber/fiber/tree/main/middleware/limiter)             | Adds Rate-limiting support to Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset.                                             |\n| [logger](https://github.com/gofiber/fiber/tree/main/middleware/logger)               | HTTP request/response logger.                                                                                                                                           |\n| [pprof](https://github.com/gofiber/fiber/tree/main/middleware/pprof)                 | Serves runtime profiling data in pprof format.                                                                                                                          |\n| [proxy](https://github.com/gofiber/fiber/tree/main/middleware/proxy)                 | Allows you to proxy requests to multiple servers.                                                                                                                       |\n| [recover](https://github.com/gofiber/fiber/tree/main/middleware/recover)             | Recovers from panics anywhere in the stack chain and handles the control to the centralized ErrorHandler.                                                               |\n| [redirect](https://github.com/gofiber/fiber/tree/main/middleware/redirect)           | Redirect middleware.                                                                                                                                                    |\n| [requestid](https://github.com/gofiber/fiber/tree/main/middleware/requestid)         | Adds a request ID to every request.                                                                                                                                     |\n| [responsetime](https://github.com/gofiber/fiber/tree/main/middleware/responsetime)   | Measures request handling duration and writes it to a configurable response header.                          |\n| [rewrite](https://github.com/gofiber/fiber/tree/main/middleware/rewrite)             | Rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links.                        |\n| [session](https://github.com/gofiber/fiber/tree/main/middleware/session)             | Session middleware. NOTE: This middleware uses our Storage package.                                                                                                     |\n| [skip](https://github.com/gofiber/fiber/tree/main/middleware/skip)                   | Skip middleware that skips a wrapped handler if a predicate is true.                                                                                                    |\n| [static](https://github.com/gofiber/fiber/tree/main/middleware/static)               | Static middleware for Fiber that serves static files such as **images**, **CSS**, and **JavaScript**.                                                                    |\n| [timeout](https://github.com/gofiber/fiber/tree/main/middleware/timeout)             | Adds a max time for a request and forwards to ErrorHandler if it is exceeded.                                                                                           |\n\n## 🧬 External Middleware\n\nList of externally hosted middleware modules and maintained by the [Fiber team](https://github.com/orgs/gofiber/people).\n\n| Middleware                                        | Description                                                                                                           |\n| :------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------- |\n| [contrib](https://github.com/gofiber/contrib)   | Third-party middlewares                                                                                               |\n| [storage](https://github.com/gofiber/storage)   | Premade storage drivers that implement the Storage interface, designed to be used with various Fiber middlewares.     |\n| [template](https://github.com/gofiber/template) | This package contains 9 template engines that can be used with Fiber.      |\n\n## 🕶️ Awesome List\n\nFor more articles, middlewares, examples, or tools, check our [awesome list](https://github.com/gofiber/awesome-fiber).\n\n## 👍 Contribute\n\nIf you want to say **Thank You** and/or support the active development of `Fiber`:\n\n1. Add a [GitHub Star](https://github.com/gofiber/fiber/stargazers) to the project.\n2. Tweet about the project [on your 𝕏 (Twitter)](https://x.com/intent/tweet?text=Fiber%20is%20an%20Express%20inspired%20%23web%20%23framework%20built%20on%20top%20of%20Fasthttp%2C%20the%20fastest%20HTTP%20engine%20for%20%23Go.%20Designed%20to%20ease%20things%20up%20for%20%23fast%20development%20with%20zero%20memory%20allocation%20and%20%23performance%20in%20mind%20%F0%9F%9A%80%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber).\n3. Write a review or tutorial on [Medium](https://medium.com/), [Dev.to](https://dev.to/) or your personal blog.\n4. Support the project by donating a [cup of coffee](https://buymeacoff.ee/fenny).\n\n## 💻 Development\n\nTo ensure your contributions are ready for a Pull Request, please use the following `Makefile` commands. These tools help maintain code quality and consistency.\n\n- **make help**: Display available commands.\n- **make audit**: Conduct quality checks.\n- **make benchmark**: Benchmark code performance.\n- **make coverage**: Generate test coverage report.\n- **make format**: Automatically format code.\n- **make lint**: Run lint checks.\n- **make test**: Execute all tests.\n- **make tidy**: Tidy dependencies.\n\nRun these commands to ensure your code adheres to project standards and best practices.\n\n## ☕ Supporters\n\nFiber 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**](https://buymeacoff.ee/fenny).\n\n|                                                            | User                                             | Donation |\n| ---------------------------------------------------------- | ------------------------------------------------ | -------- |\n| ![](https://avatars.githubusercontent.com/u/204341?s=25)   | [@destari](https://github.com/destari)           | ☕ x 10   |\n| ![](https://avatars.githubusercontent.com/u/63164982?s=25) | [@dembygenesis](https://github.com/dembygenesis) | ☕ x 5    |\n| \u003cimg src=\"https://avatars.githubusercontent.com/u/56607882?s=25\" alt=\"thomasvvugt\" style=\"width: 25px; height: 25px;\"\u003e | [@thomasvvugt](https://github.com/thomasvvugt)   | ☕ x 5    |\n| ![](https://avatars.githubusercontent.com/u/27820675?s=25) | [@hendratommy](https://github.com/hendratommy)   | ☕ x 5    |\n| ![](https://avatars.githubusercontent.com/u/1094221?s=25)  | [@ekaputra07](https://github.com/ekaputra07)     | ☕ x 5    |\n| ![](https://avatars.githubusercontent.com/u/194590?s=25)   | [@jorgefuertes](https://github.com/jorgefuertes) | ☕ x 5    |\n| ![](https://avatars.githubusercontent.com/u/186637?s=25)   | [@candidosales](https://github.com/candidosales) | ☕ x 5    |\n| ![](https://avatars.githubusercontent.com/u/29659953?s=25) | [@l0nax](https://github.com/l0nax)               | ☕ x 3    |\n| ![](https://avatars.githubusercontent.com/u/635852?s=25)   | [@bihe](https://github.com/bihe)                 | ☕ x 3    |\n| ![](https://avatars.githubusercontent.com/u/307334?s=25)   | [@justdave](https://github.com/justdave)         | ☕ x 3    |\n| ![](https://avatars.githubusercontent.com/u/11155743?s=25) | [@koddr](https://github.com/koddr)               | ☕ x 1    |\n| ![](https://avatars.githubusercontent.com/u/29042462?s=25) | [@lapolinar](https://github.com/lapolinar)       | ☕ x 1    |\n| ![](https://avatars.githubusercontent.com/u/2978730?s=25)  | [@diegowifi](https://github.com/diegowifi)       | ☕ x 1   |\n| ![](https://avatars.githubusercontent.com/u/44171355?s=25) | [@ssimk0](https://github.com/ssimk0)             | ☕ x 1   |\n| ![](https://avatars.githubusercontent.com/u/5638101?s=25)  | [@raymayemir](https://github.com/raymayemir)     | ☕ x 1   |\n| ![](https://avatars.githubusercontent.com/u/619996?s=25)   | [@melkorm](https://github.com/melkorm)           | ☕ x 1   |\n| ![](https://avatars.githubusercontent.com/u/31022056?s=25) | [@marvinjwendt](https://github.com/marvinjwendt) | ☕ x 1   |\n| ![](https://avatars.githubusercontent.com/u/31921460?s=25) | [@toishy](https://github.com/toishy)             | ☕ x 1   |\n\n## 💻 Code Contributors\n\n\u003cimg src=\"https://opencollective.com/fiber/contributors.svg?width=890\u0026button=false\" alt=\"Code Contributors\" style=\"max-width:100%;\"\u003e\n\n## ⭐️ Stargazers\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=gofiber/fiber\u0026type=Date\u0026theme=dark\" /\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=gofiber/fiber\u0026type=Date\" /\u003e\n  \u003cimg src=\"https://api.star-history.com/svg?repos=gofiber/fiber\u0026type=Date\" /\u003e\n\u003c/picture\u003e\n\n## 🧾 License\n\nCopyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](https://github.com/gofiber/fiber/graphs/contributors). `Fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/blob/main/LICENSE). Official logo was created by [Vic Shóstak](https://github.com/koddr) and distributed under [Creative Commons](https://creativecommons.org/licenses/by-sa/4.0/) license (CC BY-SA 4.0 International).\n","funding_links":["https://github.com/sponsors/gofiber"],"categories":["Go","开源类库","Web Frameworks","Programming","Backend Go","Web frameworks","Open source library","Web Development","Framework and Libraries","HarmonyOS","web框架","Service Toolkits","后端开发框架及项目","Web框架","Utility","rest-api","Examples","Popular","API Frameworks","Repositories","Included Frameworks","Web 框架","web框架`web 框架`"],"sub_categories":["Web 框架","Utility/Miscellaneous","Golang","Web Framework","Windows Manager","版本控制","Go","管理面板","实用程序/Miscellaneous","HTTP Clients","Fail injection","版本控制`版本控制相关库`"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgofiber%2Ffiber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgofiber%2Ffiber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgofiber%2Ffiber/lists"}