https://github.com/joeshaw/httpmethodoverride
Go package to override the HTTP method with value in `_method` URL query parameter
https://github.com/joeshaw/httpmethodoverride
golang http
Last synced: 4 months ago
JSON representation
Go package to override the HTTP method with value in `_method` URL query parameter
- Host: GitHub
- URL: https://github.com/joeshaw/httpmethodoverride
- Owner: joeshaw
- License: mit
- Created: 2014-08-21T14:16:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-21T14:18:30.000Z (over 11 years ago)
- Last Synced: 2025-10-01T05:25:16.139Z (4 months ago)
- Topics: golang, http
- Language: Go
- Size: 121 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httpmethodoverride #
`httpmethodoverride` is a Go package that provides an `http.Handle`
wrapper that allows clients to override the provided HTTP method with
the value within a `_method` query parameter.
Some situations in which you might want this:
* Your client stack places silly restrictions on your use, like
preventing a body in `DELETE` requests.
* You are in a browser and get redirected from a `POST` to a `GET`
but you still want to hit a `POST` API.
If you use this with a router that does method-based routing, as long
as you wrap the toplevel router/muxer in
`httpmethodoverride.Handler()` things will work exactly as if the
actual request were made with the desired HTTP method.
## API ##
```go
mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func w http.ResponseWriter, r *http.Request) {
w.Write([]byte(r.Method))
})
http.ListenAndServe(":8000", httpmethodoverride.Handler(mux))
```
That's it. But it's also
[on godoc](http://godoc.org/github.com/joeshaw/httpmethodoverride).
```
$ curl http://localhost:8080/
GET
```
```
$ curl http://localhost:8080/?_method=POST
POST
```