Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 5, 2024 via pnpm

method-override 2.3.10

Override HTTP verbs
Package summary
Share
0
issues
1
license
6
MIT
Package created
3 Mar 2014
Version published
27 Sep 2017
Maintainers
5
Total deps
6
Direct deps
4
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
6 Packages, Including:
debug@2.6.9
method-override@2.3.10
methods@1.1.2
ms@2.0.0
parseurl@1.3.3
vary@1.1.2
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

4
All Dependencies CSV
β“˜ This is a list of method-override 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
debug2.6.916.13 kBMIT
prod
methods1.1.22.42 kBMIT
prod
parseurl1.3.33.86 kBMIT
prod
vary1.1.23.68 kBMIT
prod

Visualizations

Frequently Asked Questions

What does method-override do?

The method-override package is a Node.js module facilitating the use of HTTP verbs such as PUT or DELETE where the client doesn't traditionally support it. It lets developers override the HTTP method sent in the request header using a simple middleware setup in Express.js. This is especially useful when dealing with older browsers or HTTP clients that only support GET and POST methods.

How do you use method-override?

Using method-override primarily involves setting up a middleware to override the HTTP method. The middleware function overrides the req.method property with a new value, obtained from a specified getter. You may choose to use a header or a query string value to indicate the override method. Here's how you include and use it in an Express.js setup:

var express = require('express')
var methodOverride = require('method-override')
var app = express()

// override with the X-HTTP-Method-Override header in the request
app.use(methodOverride('X-HTTP-Method-Override')) 

You can then make a POST request with the desired method indicated in the X-HTTP-Method-Override header. Multiple format support is also possible, using different headers where the last one takes precedence.

The following adds an additional layer of customization, allowing for an override using the _method key in the req.body object:

var bodyParser = require('body-parser')
var express = require('express')
var methodOverride = require('method-override')
var app = express()

app.use(bodyParser.urlencoded())
app.use(methodOverride(function (req, res) {
  if (req.body && typeof req.body === 'object' && '_method' in req.body) {
    var method = req.body._method
    delete req.body._method
    return method
  }
}))  

Please note that req.body must be fully parsed before calling methodOverride() in your middleware stack, otherwise req.body won't be populated.

Where are the method-override docs?

You can find the method-override documentation on its npm page at npmjs.org/package/method-override. This includes detailed information on how to setup and use the module, options available for customization, and various examples of method overrides. Additional information can be found at the source repository at https://github.com/expressjs/method-override.