HTTP Method Override

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.


package main

import (

func main() {
    app := iris.New() 

    mo := methodoverride.New( 
        // Defaults to nil. 
        // 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.Post("/path", func(ctx iris.Context) {
        ctx.WriteString("post response")

    app.Delete("/path", func(ctx iris.Context) {
        ctx.WriteString("delete response")

    // []


fetch("/path", {
    method: 'POST',
    headers: {
      "X-HTTP-Method": "DELETE"
      // response body will be "delete response". 
 })).catch((err)=> { console.error(err) })

Last updated