{"id":13713925,"url":"https://github.com/kataras/methodoverride","last_synced_at":"2025-04-11T03:50:47.983Z","repository":{"id":57562356,"uuid":"224303863","full_name":"kataras/methodoverride","owner":"kataras","description":":new: Lets you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it","archived":false,"fork":false,"pushed_at":"2022-12-24T06:22:16.000Z","size":17,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T01:51:09.726Z","etag":null,"topics":["go","golang","http","methodoverride","middleware","nethttp"],"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/kataras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"kataras"}},"created_at":"2019-11-26T23:22:04.000Z","updated_at":"2024-05-21T12:16:04.000Z","dependencies_parsed_at":"2023-01-30T20:10:16.760Z","dependency_job_id":null,"html_url":"https://github.com/kataras/methodoverride","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/kataras%2Fmethodoverride","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fmethodoverride/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fmethodoverride/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fmethodoverride/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kataras","download_url":"https://codeload.github.com/kataras/methodoverride/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339262,"owners_count":21087214,"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","methodoverride","middleware","nethttp"],"created_at":"2024-08-02T23:01:47.803Z","updated_at":"2025-04-11T03:50:47.965Z","avatar_url":"https://github.com/kataras.png","language":"Go","readme":"# HTTP Method Override (Go)\r\n\r\n[![build status](https://img.shields.io/github/actions/workflow/status/kataras/methodoverride/ci.yml?style=for-the-badge)](https://github.com/kataras/methodoverride/actions) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/methodoverride) [![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/methodoverride)\r\n\r\nThe use of specific custom HTTP headers such as X-HTTP methods override can be very handy while developing and promoting a REST API. When deploying REST API based web services, you may encounter access limitations on both the server and client sides.\r\n\r\n**Some Firewalls do not support PUT, DELETE or PATCH requests.**\r\n\r\nThe `methodoverride` package is a [net/http](https://pkg.go.dev/net/http) middleware. **It lets you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it**.\r\n\r\n## Getting started\r\n\r\nThe only requirement is the [Go Programming Language](https://go.dev/dl/).\r\n\r\n```sh\r\n$ go get github.com/kataras/methodoverride\r\n```\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n    \"net/http\"\r\n\r\n    \"github.com/kataras/methodoverride\"\r\n)\r\n\r\nfunc main() {\r\n    router := http.NewServeMux()\r\n\r\n    mo := methodoverride.New( \r\n        // Defaults to nil. \r\n        // \r\n        methodoverride.SaveOriginalMethod(\"_originalMethod\"), \r\n        // Default values. \r\n        // \r\n        // methodoverride.Methods(http.MethodPost), \r\n        // methodoverride.Headers(\"X-HTTP-Method\",\r\n        //                        \"X-HTTP-Method-Override\",\r\n        //                        \"X-Method-Override\"), \r\n        // methodoverride.FormField(\"_method\"), \r\n        // methodoverride.Query(\"_method\"), \r\n    ) \r\n\r\n    router.HandleFunc(\"/path\", func(w http.ResponseWriter, r *http.Request) {\r\n        resp := \"post response\"\r\n\r\n        if r.Method == http.MethodDelete {\r\n            resp = \"delete response\"\r\n        }\r\n\r\n        w.Write([]byte(resp))\r\n    })\r\n\r\n    // Wrap your \"router\" with the methodoverride wrapper. \r\n    http.ListenAndServe(\":8080\", mo(router))\r\n}\r\n\r\n```\r\n\r\nA **client** can request with POST, the server will respond like if it were a DELETE method.\r\n\r\n```js\r\nfetch(\"/path\", {\r\n    method: 'POST',\r\n    headers: {\r\n      \"X-HTTP-Method\": \"DELETE\"\r\n    },\r\n  })\r\n  .then((resp)=\u003e{\r\n      // response body will be \"delete response\". \r\n })).catch((err)=\u003e { console.error(err) })\r\n```\r\n\r\n## License\r\n\r\nMethodoverride is free and open-source software licensed under the [MIT License](https://tldrlegal.com/license/mit-license).\r\n","funding_links":["https://github.com/sponsors/kataras"],"categories":["Repositories"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fmethodoverride","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkataras%2Fmethodoverride","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fmethodoverride/lists"}