{"id":17138868,"url":"https://github.com/alexedwards/flow","last_synced_at":"2025-05-15T13:08:55.890Z","repository":{"id":40300464,"uuid":"421918843","full_name":"alexedwards/flow","owner":"alexedwards","description":"A delightfully tiny but powerful HTTP router for Go web applications","archived":false,"fork":false,"pushed_at":"2025-04-04T17:24:47.000Z","size":230,"stargazers_count":400,"open_issues_count":2,"forks_count":20,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-08T01:34:21.621Z","etag":null,"topics":["go","golang","http","mux","router","routing"],"latest_commit_sha":null,"homepage":"","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/alexedwards.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-27T17:48:18.000Z","updated_at":"2025-04-06T07:52:00.000Z","dependencies_parsed_at":"2025-03-24T23:37:23.436Z","dependency_job_id":null,"html_url":"https://github.com/alexedwards/flow","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexedwards%2Fflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexedwards%2Fflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexedwards%2Fflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexedwards%2Fflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexedwards","download_url":"https://codeload.github.com/alexedwards/flow/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346625,"owners_count":22055808,"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":["go","golang","http","mux","router","routing"],"created_at":"2024-10-14T20:10:48.038Z","updated_at":"2025-05-15T13:08:50.882Z","avatar_url":"https://github.com/alexedwards.png","language":"Go","readme":"\u003cdiv align=\"center\"\u003e\n\n![Flow](https://raw.githubusercontent.com/alexedwards/flow/assets/flow-sm.png)\n        \n[![Go Reference](https://pkg.go.dev/badge/github.com/alexedwards/flow.svg)](https://pkg.go.dev/github.com/alexedwards/flow) [![Go Report Card](https://goreportcard.com/badge/github.com/alexedwards/flow)](https://goreportcard.com/report/github.com/alexedwards/flow) [![MIT](https://img.shields.io/github/license/alexedwards/flow)](https://img.shields.io/github/license/alexedwards/flow) ![Code size](https://img.shields.io/github/languages/code-size/alexedwards/flow)\n\nA delightfully tiny but powerful HTTP router for Go web applications\n\u003c/div\u003e\n\n---\n\nFlow packs in a bunch of features that you'll probably like:\n\n* Use **named parameters**, **wildcards** and (optionally) **regexp patterns** in your routes.\n* Create route **groups which use different middleware** (a bit like chi).\n* **Customizable handlers** for `404 Not Found` and `405 Method Not Allowed` responses.\n* **Automatic handling** of `OPTIONS` and `HEAD` requests.\n* Works with `http.Handler`, `http.HandlerFunc`, and standard Go middleware.\n* Zero dependencies.\n* Tiny, readable, codebase (~160 lines of code).\n\n---\n\n### Project status\n\nThis package has reached a **stable** status. It is actively maintained with ongoing bug fixes and essential updates, but significant alterations to the API or behavior are not expected.\n\n---\n\n### Installation\n\n```\n$ go get github.com/alexedwards/flow@latest\n```\n\n### Basic example\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"net/http\"\n\n    \"github.com/alexedwards/flow\"\n)\n\nfunc main() {\n    // Initialize a new router.\n    mux := flow.New()\n\n    // Add a `GET /greet/:name` route. The : character is used to denote a \n    // named parameter in the URL path, which acts like a 'wildcard'.\n    mux.HandleFunc(\"/greet/:name\", greet, \"GET\")\n\n    err := http.ListenAndServe(\":2323\", mux)\n    log.Fatal(err)\n}\n\nfunc greet(w http.ResponseWriter, r *http.Request) {\n    // Retrieve the value of the named parameter from the request.\n    name := r.PathValue(\"name\")\n\n    fmt.Fprintf(w, \"Hello %s\", name)\n}\n```\n\n### Kitchen-sink example\n\n```go\nmux := flow.New()\n\n// The Use() method can be used to register middleware. Middleware declared at\n// the top level will be used on all routes (including error handlers and OPTIONS\n// responses).\nmux.Use(exampleMiddleware1)\n\n// Routes can use multiple HTTP methods.\nmux.HandleFunc(\"/profile/:name\", exampleHandlerFunc1, \"GET\", \"POST\")\n\n// Optionally, regular expressions can be used to enforce a specific pattern\n// for a named parameter.\nmux.HandleFunc(\"/profile/:name/:age|^[0-9]{1,3}$\", exampleHandlerFunc2, \"GET\")\n\n// The wildcard ... can be used to match the remainder of a request path.\n// Notice that HTTP methods are also optional (if not provided, all HTTP\n// methods will match the route). The value of the wildcard can be retrieved \n// by calling r.PathValue(\"...\").\nmux.Handle(\"/static/...\", exampleHandler)\n\n// You can create route 'groups'.\nmux.Group(func(mux *flow.Mux) {\n    // Middleware declared within the group will only be used on the routes\n    // in the group.\n    mux.Use(exampleMiddleware2)\n\n    mux.HandleFunc(\"/admin\", exampleHandlerFunc3, \"GET\")\n\n    // Groups can be nested.\n    mux.Group(func(mux *flow.Mux) {\n        mux.Use(exampleMiddleware3)\n\n        mux.HandleFunc(\"/admin/passwords\", exampleHandlerFunc4, \"GET\")\n    })\n})\n```\n\n### Notes\n\n* Conflicting routes are permitted (e.g. `/posts/:id` and `posts/new`). Routes are matched in the order that they are declared.\n* Trailing slashes are significant (`/profile/:id` and `/profile/:id/` are not the same).\n* An `Allow` header is automatically set for all `OPTIONS` and `405 Method Not Allowed` responses (including when using custom handlers). \n* Once the `flow.Mux` type is being used by your server, it is *not safe* to add more middleware or routes concurrently.\n* Middleware must be declared *before* a route in order to be used by that route. Any middleware declared after a route won't act on that route. For example:\n\n```go\nmux := flow.New()\nmux.Use(middleware1)\nmux.HandleFunc(\"/foo\", ...) // This route will use middleware1 only.\nmux.Use(middleware2)\nmux.HandleFunc(\"/bar\", ...) // This route will use both middleware1 and middleware2.\n```\n\n### Thanks\n\nThe pattern matching logic for Flow was heavily inspired by [matryer/way](https://github.com/matryer/way).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexedwards%2Fflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexedwards%2Fflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexedwards%2Fflow/lists"}