Skip to content

MethodOverride middleware for Gin web framework

License

Notifications You must be signed in to change notification settings

bu/gin-method-override

Repository files navigation

Gin MethodOverride Middleware

Go Report Card Build Status

A Gin web framework middleware for method override by POST form param _method, inspired by Ruby's same name rack

Usage

Server-side

package main

import (
	gin "github.com/gin-gonic/gin"
	method "github.com/bu/gin-method-override"
)

func main() {
	// create a Gin engine
	r := gin.Default()

	// our middle-ware
	r.Use(method.ProcessMethodOverride(r))

	// routes
	r.PUT("/test", func (c *gin.Context) {
		c.String(200, "1")
	})

	// listen to request
	r.Run(":8080")
}

Client side

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
    <form action="/test" method="POST"> <!-- form method rewrite only works with POST request -->
        <input type="hidden" name="_method" value="PUT">
        <input type="text" name="testing" value="1">
        <button type="submit">Send</button>
    </form>
</body>
</html>

About

MethodOverride middleware for Gin web framework

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published