{"id":17231788,"url":"https://github.com/pierreprinetti/go-methodmux","last_synced_at":"2025-03-26T00:24:34.101Z","repository":{"id":74418125,"uuid":"124664791","full_name":"pierreprinetti/go-methodmux","owner":"pierreprinetti","description":"A method-aware HTTP request multiplexer based on net/http","archived":false,"fork":false,"pushed_at":"2018-03-10T17:12:07.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T23:34:08.340Z","etag":null,"topics":["http","http-method","mux","server"],"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/pierreprinetti.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":"2018-03-10T14:44:25.000Z","updated_at":"2019-09-10T21:11:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"a6a81008-fcac-4d0c-a7dd-8b357e1db741","html_url":"https://github.com/pierreprinetti/go-methodmux","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreprinetti%2Fgo-methodmux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreprinetti%2Fgo-methodmux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreprinetti%2Fgo-methodmux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pierreprinetti%2Fgo-methodmux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pierreprinetti","download_url":"https://codeload.github.com/pierreprinetti/go-methodmux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236422784,"owners_count":19146323,"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":["http","http-method","mux","server"],"created_at":"2024-10-15T04:58:55.330Z","updated_at":"2025-01-30T21:15:54.902Z","avatar_url":"https://github.com/pierreprinetti.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Methodmux\n[![GoDoc](https://godoc.org/github.com/pierreprinetti/go-methodmux?status.svg)](http://godoc.org/github.com/pierreprinetti/go-methodmux)\n[![Build Status](https://travis-ci.org/pierreprinetti/go-methodmux.svg?branch=master)](https://travis-ci.org/pierreprinetti/go-methodmux)\n[![Go Report Card](https://goreportcard.com/badge/github.com/pierreprinetti/go-methodmux)](https://goreportcard.com/report/github.com/pierreprinetti/go-methodmux)\n[![Coverage Status](https://coveralls.io/repos/github/pierreprinetti/go-methodmux/badge.svg?branch=master)](https://coveralls.io/github/pierreprinetti/go-methodmux?branch=master)\n\nMethodmux is a method-aware HTTP router based on net/http.\n\nMethodmux exposes a single type: `ServeMux`. `ServeMux` holds a separate `http.ServeMux` for every HTTP verb an http.Handler has been registered to.\n\nEvery new request will be matched against the underlying `http.ServeMux` that corresponds to the HTTP method of the request.\nIf no match is found, `ServeMux` will look for a match in the other HTTP verbs. If a match is found, an HTTP code 405 \"Method Not Allowed\" is returned. If not, an HTTP code 404 \"Not Found\" is returned.\n\nMethodmux has been written with readability in mind and is just as fast and efficient as `net/http` is.\n\n## API\n\n* `func New() *ServeMux`: allocates and returns a new ServeMux.\n* `func (mux *ServeMux) Handle(method, pattern string, handler http.Handler)`: registers the handler for the given method and pattern.\n* `func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)`: dispatches the request to the handler registered with the HTTP method of the request, and whose pattern most closely matches the request URL.\n\n## Usage\n\n```Go\npackage main\n\nimport (\n\t\"net/http\"\n\n\tmethodmux \"github.com/pierreprinetti/go-methodmux\"\n)\n\nfunc main() {\n\tmux := methodmux.New()\n\n\tmux.Handle(http.MethodGet, \"/some-endpoint/\", getHandler)\n\tmux.Handle(\"MYMETHOD\", \"/some-endpoint/\", myMethodHandler)\n\tmux.HandleFunc(http.MethodPost, \"/some-endpoint/\", func(rw http.ResponseWriter, req *http.Request) {\n\t\tfmt.Fprintf(rw, \"Hi! This the response to a POST call.\")\n\t})\n\n\tsrv := \u0026http.Server{\n\t\tHandler:        mux,\n\t\tReadTimeout:    10 * time.Second,\n\t\tWriteTimeout:   10 * time.Second,\n\t\tMaxHeaderBytes: 1 \u003c\u003c 20,\n\t}\n\n\tlog.Fatal(srv.ListenAndServe())\n}\n```\n\nUse godoc for more detailed documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpierreprinetti%2Fgo-methodmux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpierreprinetti%2Fgo-methodmux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpierreprinetti%2Fgo-methodmux/lists"}