method

package
v0.0.0-...-56ccf34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2017 License: MIT Imports: 2 Imported by: 0

README

Method

Middleware/handler for handling http method overrides. This checks for the X-HTTP-Method-Override header and uses it if the original reqeust method is POST. GET/HEAD methods shouldn't be overriden, hence they can't be overriden.

This is useful for REST APIs and services making use of many HTTP verbs, and when the HTTP clients don't support all of them.

Installation

go get github.com/syntaqx/echo-middleware/method

Usage

package main

import (
    "github.com/labstack/echo"
    "github.com/syntaqx/echo-middleware/method"
)

func main() {
    e := echo.New()

    // Attach middleware
    e.Use(method.Override())

    e.Run(":8080")
}

Documentation

Overview

Method implements the ability to override HTTP methods This package was created from github.com/codegangsta/martini-contrib/method and modified to work with the echo framework

Index

Constants

View Source
const HeaderHTTPMethodOverride = "X-HTTP-Method-Override"

HeaderHTTPMethodOVerride is a common HTTP header used to override the HTTP method

View Source
const ParamHTTPMethodOverride = "_method"

ParamHTTPMethodOverride is a common used HTTML form parameter used to override the HTTP method

Variables

View Source
var ErrInvalidOverrideMethod = errors.New("invalid override method")

ErrInvalidOverrideMethod is returned when an invalid http method was given to OverrideRequestMethod.

Functions

func Override

func Override() echo.HandlerFunc

Override checks for the X-HTTP-Method-Override header or the HTML for parameter, `_method` and uses (if valid) the http method instead of Request.Method. This is especially useful for http clients that don't support many http verbs. It isn't secure to override e.g a GET to a POST, so only Request.Method which are POSTs are considered.

func OverrideRequestMethod

func OverrideRequestMethod(c *echo.Context, method string) error

OverrideRequestMethod overrides the http request's method with the specified method.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL