mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Page:
HTTP method override
Pages
API versioning
Automatic public address
Benchmarks
Cache
Configuration
Content negotiation
Cookies
Documentation terms and conditions
Forms
Grpc
HTTP method override
HTTP referrer
Home
Host
Installation
Localization
MVC
Model validation
Our users
Project and community
Publications
Quick start
Request authentication
Response recorder
Routing context methods
Routing error handlers
Routing middleware
Routing override context
Routing path parameter types
Routing reverse lookups
Routing subdomains
Routing wrap the router
Routing
Sessions database
Sessions flash messages
Sessions
Sitemap
Starter kits
Support
Testing
URL query parameters
View
Websockets
dependency injection
2
HTTP method override
Gerasimos (Makis) Maropoulos edited this page 2019-11-22 15:02:55 +02:00
The 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.
Some Firewalls do not support PUT, DELETE or PATCH requests.
The Method Override wrapper lets you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it.
Server
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/methodoverride"
)
func main() {
app := iris.New()
mo := methodoverride.New(
// Defaults to nil.
//
methodoverride.SaveOriginalMethod("_originalMethod"),
// Default values.
//
// methodoverride.Methods(http.MethodPost),
// methodoverride.Headers("X-HTTP-Method",
// "X-HTTP-Method-Override",
// "X-Method-Override"),
// methodoverride.FormField("_method"),
// methodoverride.Query("_method"),
)
// Register it with `WrapRouter`.
app.WrapRouter(mo)
app.Post("/path", func(ctx iris.Context) {
ctx.WriteString("post response")
})
app.Delete("/path", func(ctx iris.Context) {
ctx.WriteString("delete response")
})
// [...app.Run]
}
Client
fetch("/path", {
method: 'POST',
headers: {
"X-HTTP-Method": "DELETE"
},
})
.then((resp)=>{
// response body will be "delete response".
})).catch((err)=> { console.error(err) })
- What is Iris
- 📌Getting Started
- Host
- Configuration
- Routing
- HTTP Method Override
- API Versioning
- Content Negotiation
- Response Recorder
- HTTP Referrer
- Request Authentication
- URL Query Parameters
- Forms
- Model Validation
- Cache
- View
- Cookies
- Sessions
- Websockets
- Dependency Injection
- MVC
- gRPC
- Sitemap
- Localization
- Testing
- 🤓Resources
Home | Project | Quick Start | Technical Docs | Copyright © 2019-2020 Gerasimos Maropoulos. Documentation terms of use.