{"id":13676573,"url":"https://github.com/fasthttp/router","last_synced_at":"2026-01-15T01:01:54.218Z","repository":{"id":34736852,"uuid":"153124788","full_name":"fasthttp/router","owner":"fasthttp","description":"Router implementation for fasthttp","archived":false,"fork":false,"pushed_at":"2025-01-01T23:00:11.000Z","size":464,"stargazers_count":493,"open_issues_count":4,"forks_count":51,"subscribers_count":14,"default_branch":"master","last_synced_at":"2026-01-12T01:36:48.977Z","etag":null,"topics":["fast","fasthttp","go","golang","performance","radix-tree","router","routing","routing-engine"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"buaazp/fasthttprouter","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fasthttp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-10-15T14:09:19.000Z","updated_at":"2025-12-29T07:14:34.000Z","dependencies_parsed_at":"2023-11-17T14:10:20.185Z","dependency_job_id":"5ff0ec17-79bd-4b1e-9518-8257646ae4e6","html_url":"https://github.com/fasthttp/router","commit_stats":{"total_commits":355,"total_committers":47,"mean_commits":7.553191489361702,"dds":0.6845070422535211,"last_synced_commit":"e572ed52173bcde8462d31ece9bcc7983480b4e8"},"previous_names":["fasthttp/fasthttprouter"],"tags_count":80,"template":false,"template_full_name":null,"purl":"pkg:github/fasthttp/router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fasthttp%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fasthttp%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fasthttp%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fasthttp%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fasthttp","download_url":"https://codeload.github.com/fasthttp/router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fasthttp%2Frouter/sbom","scorecard":{"id":393327,"data":{"date":"2025-08-11","repo":{"name":"github.com/fasthttp/router","commit":"a90f305c450b81b40943f41904d685d243766b02"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.1,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/fasthttp/router/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/fasthttp/router/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/fasthttp/router/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/fasthttp/router/test.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T18:22:26.611Z","repository_id":34736852,"created_at":"2025-08-18T18:22:26.611Z","updated_at":"2025-08-18T18:22:26.611Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"ssl_error","status_checked_at":"2026-01-15T00:55:20.945Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["fast","fasthttp","go","golang","performance","radix-tree","router","routing","routing-engine"],"created_at":"2024-08-02T13:00:29.878Z","updated_at":"2026-01-15T01:01:54.158Z","avatar_url":"https://github.com/fasthttp.png","language":"Go","funding_links":[],"categories":["Multiplexers","Go"],"sub_categories":[],"readme":"# Router\n\n[![Test status](https://github.com/fasthttp/router/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/fasthttp/router/actions?workflow=test)\n[![Coverage Status](https://coveralls.io/repos/fasthttp/router/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/fasthttp/router?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/fasthttp/router)](https://goreportcard.com/report/github.com/fasthttp/router)\n[![GoDev](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/fasthttp/router)\n[![GitHub release](https://img.shields.io/github/release/fasthttp/router.svg)](https://github.com/fasthttp/router/releases)\n\nRouter is a lightweight high performance HTTP request router (also called _multiplexer_ or just _mux_ for short) for [fasthttp](https://github.com/valyala/fasthttp).\n\nThis router is optimized for high performance and a small memory footprint. It scales well even with very long paths and a large number of routes. A compressing dynamic trie (radix tree) structure is used for efficient matching.\n\nBased on [julienschmidt/httprouter](https://github.com/julienschmidt/httprouter).\n\n## Features\n\n**Best Performance:** Router is **one of the fastest** go web frameworks in the [go-web-framework-benchmark](https://github.com/smallnest/go-web-framework-benchmark). Even faster than httprouter itself.\n\n- Basic Test: The first test case is to mock 0 ms, 10 ms, 100 ms, 500 ms processing time in handlers.\n\n![](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/master/benchmark.png)\n\n- Concurrency Test (allocations): In 30 ms processing time, the test result for 100, 1000, 5000 clients is:\n\n\\* _Smaller is better_\n\n![](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/master/concurrency_alloc.png)\n\nSee below for technical details of the implementation.\n\n**Only explicit matches:** With other routers, like [http.ServeMux](http://golang.org/pkg/net/http/#ServeMux),\na requested URL path could match multiple patterns. Therefore they have some\nawkward pattern priority rules, like _longest match_ or _first registered,\nfirst matched_. By design of this router, a request can only match exactly one\nor no route. As a result, there are also no unintended matches, which makes it\ngreat for SEO and improves the user experience.\n\n**Stop caring about trailing slashes:** Choose the URL style you like, the\nrouter automatically redirects the client if a trailing slash is missing or if\nthere is one extra. Of course it only does so, if the new path has a handler.\n**If** you don't like it, you can [turn off this behavior](https://pkg.go.dev/github.com/fasthttp/router#Router.RedirectTrailingSlash).\n\n**Path auto-correction:** Besides detecting the missing or additional trailing\nslash at no extra cost, the router can also fix wrong cases and remove\nsuperfluous path elements (like `../` or `//`).\nIs [CAPTAIN CAPS LOCK](http://www.urbandictionary.com/define.php?term=Captain+Caps+Lock) one of your users?\nRouter can help him by making a case-insensitive look-up and redirecting him\nto the correct URL.\n\n**Parameters in your routing pattern:** Stop parsing the requested URL path,\njust give the path segment a name and the router delivers the dynamic value to\nyou. Because of the design of the router, path parameters are very cheap.\n\n**Zero Garbage:** The matching and dispatching process generates zero bytes of\ngarbage. In fact, the only heap allocations that are made, is by building the\nslice of the key-value pairs for path parameters. If the request path contains\nno parameters, not a single heap allocation is necessary.\n\n**No more server crashes:** You can set a [Panic handler](https://pkg.go.dev/github.com/fasthttp/router#Router.PanicHandler) to deal with panics\noccurring during handling a HTTP request. The router then recovers and lets the\nPanicHandler log what happened and deliver a nice error page.\n\n**Perfect for APIs:** The router design encourages to build sensible, hierarchical\nRESTful APIs. Moreover it has builtin native support for [OPTIONS requests](http://zacstewart.com/2012/04/14/http-options-method.html)\nand `405 Method Not Allowed` replies.\n\nOf course you can also set **custom [NotFound](https://pkg.go.dev/github.com/fasthttp/router#Router.NotFound) and [MethodNotAllowed](https://pkg.go.dev/github.com/fasthttp/router#Router.MethodNotAllowed) handlers** and [**serve static files**](https://pkg.go.dev/github.com/fasthttp/router#Router.ServeFiles).\n\n## Usage\n\nThis is just a quick introduction, view the [GoDoc](https://pkg.go.dev/github.com/fasthttp/router) for details:\n\nLet's start with a trivial example:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/fasthttp/router\"\n\t\"github.com/valyala/fasthttp\"\n)\n\nfunc Index(ctx *fasthttp.RequestCtx) {\n\tctx.WriteString(\"Welcome!\")\n}\n\nfunc Hello(ctx *fasthttp.RequestCtx) {\n\tfmt.Fprintf(ctx, \"Hello, %s!\\n\", ctx.UserValue(\"name\"))\n}\n\nfunc main() {\n\tr := router.New()\n\tr.GET(\"/\", Index)\n\tr.GET(\"/hello/{name}\", Hello)\n\n\tlog.Fatal(fasthttp.ListenAndServe(\":8080\", r.Handler))\n}\n```\n\n### Named parameters\n\nAs you can see, `{name}` is a _named parameter_. The values are accessible via `RequestCtx.UserValues`. You can get the value of a parameter by using the `ctx.UserValue(\"name\")`.\n\nNamed parameters only match a single path segment:\n\n```\nPattern: /user/{user}\n\n /user/gordon                     match\n /user/you                        match\n /user/gordon/profile             no match\n /user/                           no match\n\nPattern with suffix: /user/{user}_admin\n\n /user/gordon_admin               match\n /user/you_admin                  match\n /user/you                        no match\n /user/gordon/profile             no match\n /user/gordon_admin/profile       no match\n /user/                           no match\n```\n\n#### Optional parameters\n\nIf you need define an optional parameters, add `?` at the end of param name. `{name?}`\n\n#### Regex validation\n\nIf you need define a validation, you could use a custom regex for the paramater value, add `:\u003cregex\u003e` after the name. For example: `{name:[a-zA-Z]{5}}`.\n\n**_Optional parameters and regex validation are compatibles, only add `?` between the name and the regex. For example: `{name?:[a-zA-Z]{5}}`._**\n\n### Catch-All parameters\n\nThe second type are _catch-all_ parameters and have the form `{name:*}`.\nLike the name suggests, they match everything.\nTherefore they must always be at the **end** of the pattern:\n\n```\nPattern: /src/{filepath:*}\n\n /src/                     match\n /src/somefile.go          match\n /src/subdir/somefile.go   match\n```\n\n## How does it work?\n\nThe router relies on a tree structure which makes heavy use of _common prefixes_, it is basically a _compact_ [_prefix tree_](https://en.wikipedia.org/wiki/Trie) (or just [_Radix tree_](https://en.wikipedia.org/wiki/Radix_tree)). Nodes with a common prefix also share a common parent. Here is a short example what the routing tree for the `GET` request method could look like:\n\n```\nPriority   Path             Handle\n9          \\                 *\u003c1\u003e\n3          ├s                nil\n2          |├earch\\          *\u003c2\u003e\n1          |└upport\\         *\u003c3\u003e\n2          ├blog\\            *\u003c4\u003e\n1          |    └{post}      nil\n1          |          └\\     *\u003c5\u003e\n2          ├about-us\\        *\u003c6\u003e\n1          |        └team\\   *\u003c7\u003e\n1          └contact\\         *\u003c8\u003e\n```\n\nEvery `*\u003cnum\u003e` represents the memory address of a handler function (a pointer). If you follow a path trough the tree from the root to the leaf, you get the complete route path, e.g `\\blog\\{post}\\`, where `{post}` is just a placeholder ([_parameter_](#named-parameters)) for an actual post name. Unlike hash-maps, a tree structure also allows us to use dynamic parts like the `{post}` parameter, since we actually match against the routing patterns instead of just comparing hashes. [As benchmarks show][benchmark], this works very well and efficient.\n\nSince URL paths have a hierarchical structure and make use only of a limited set of characters (byte values), it is very likely that there are a lot of common prefixes. This allows us to easily reduce the routing into ever smaller problems. Moreover the router manages a separate tree for every request method. For one thing it is more space efficient than holding a method-\u003ehandle map in every single node, for another thing is also allows us to greatly reduce the routing problem before even starting the look-up in the prefix-tree.\n\n\nFor even better scalability, the child nodes on each tree level are ordered by priority, where the priority is just the number of handles registered in sub nodes (children, grandchildren, and so on..). This helps in two ways:\n\n1. Nodes which are part of the most routing paths are evaluated first. This helps to make as much routes as possible to be reachable as fast as possible.\n2. It is some sort of cost compensation. The longest reachable path (highest cost) can always be evaluated first. The following scheme visualizes the tree structure. Nodes are evaluated from top to bottom and from left to right.\n\n```\n├------------\n├---------\n├-----\n├----\n├--\n├--\n└-\n```\n\n## Why doesn't this work with `http.Handler`?\n\nBecause fasthttp doesn't provide http.Handler. See this [description](https://github.com/valyala/fasthttp#switching-from-nethttp-to-fasthttp).\n\nFasthttp works with [RequestHandler](https://pkg.go.dev/github.com/valyala/fasthttp#RequestHandler) functions instead of objects implementing Handler interface. So a Router provides a [Handler](https://pkg.go.dev/github.com/fasthttp/router#Router.Handler) interface to implement the fasthttp.ListenAndServe interface.\n\nJust try it out for yourself, the usage of Router is very straightforward. The package is compact and minimalistic, but also probably one of the easiest routers to set up.\n\n## Where can I find Middleware _X_?\n\nThis package just provides a very efficient request router with a few extra features. The router is just a [`fasthttp.RequestHandler`](https://pkg.go.dev/github.com/valyala/fasthttp#RequestHandler), you can chain any `fasthttp.RequestHandler` compatible middleware before the router. Or you could [just write your own](https://justinas.org/writing-http-middleware-in-go/), it's very easy!\n\nHave a look at these middleware examples:\n\n- [Auth Middleware](_examples/auth)\n- [Multi Hosts Middleware](_examples/hosts)\n\n## Chaining with the NotFound handler\n\n**NOTE: It might be required to set [Router.HandleMethodNotAllowed](https://pkg.go.dev/github.com/fasthttp/router#Router.HandleMethodNotAllowed) to `false` to avoid problems.**\n\nYou can use another [fasthttp.RequestHandler](https://pkg.go.dev/github.com/valyala/fasthttp#RequestHandler), for example another router, to handle requests which could not be matched by this router by using the [Router.NotFound](https://pkg.go.dev/github.com/fasthttp/router#Router.NotFound) handler. This allows chaining.\n\n### Static files\n\nThe `NotFound` handler can for example be used to serve static files from the root path `/` (like an index.html file along with other assets):\n\n```go\n// Serve static files from the ./public directory\nr.NotFound = fasthttp.FSHandler(\"./public\", 0)\n```\n\nBut this approach sidesteps the strict core rules of this router to avoid routing problems. A cleaner approach is to use a distinct sub-path for serving files, like `/static/{filepath:*}` or `/files/{filepath:*}`.\n\n## Web Frameworks based on Router\n\nIf the Router is a bit too minimalistic for you, you might try one of the following more high-level 3rd-party web frameworks building upon the Router package:\n\n- [Atreugo](https://github.com/savsgio/atreugo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffasthttp%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffasthttp%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffasthttp%2Frouter/lists"}