Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@types/method-override
Advanced tools
@types/method-override provides TypeScript definitions for the method-override middleware, which allows you to use HTTP verbs such as PUT or DELETE in places where the client doesn't support it.
Override HTTP Methods
This feature allows you to override HTTP methods using a custom header. In this example, the middleware checks for the 'X-HTTP-Method-Override' header and uses its value to override the HTTP method.
const methodOverride = require('method-override');
const express = require('express');
const app = express();
// Override with the X-HTTP-Method-Override header in the request
app.use(methodOverride('X-HTTP-Method-Override'));
app.post('/resource', (req, res) => {
res.send('POST request to the resource');
});
app.put('/resource', (req, res) => {
res.send('PUT request to the resource');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Override using a query value
This feature allows you to override HTTP methods using a query parameter. In this example, the middleware checks for the '_method' query parameter and uses its value to override the HTTP method.
const methodOverride = require('method-override');
const express = require('express');
const app = express();
// Override with the _method query parameter in the request
app.use(methodOverride('_method'));
app.post('/resource', (req, res) => {
res.send('POST request to the resource');
});
app.put('/resource', (req, res) => {
res.send('PUT request to the resource');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Connect is a middleware framework for Node.js, offering a collection of high-performance 'plugins' known as middleware. It can be used to create a custom method override middleware similar to method-override.
Body-parser is a middleware to handle the request body in Node.js. While it doesn't directly provide method overriding, it is often used in conjunction with method-override to parse incoming request bodies before method overriding.
Express is a web application framework for Node.js. It provides a robust set of features for web and mobile applications, including routing and middleware support. Method-override is often used as middleware in Express applications.
npm install --save @types/method-override
This package contains type definitions for method-override (https://github.com/expressjs/method-override).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/method-override.
// Type definitions for method-override
// Project: https://github.com/expressjs/method-override
// Definitions by: Santi Albo <https://github.com/santialbo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
declare namespace Express {
export interface Request {
originalMethod?: string | undefined;
}
}
import express = require("express");
declare namespace e {
export interface MethodOverrideOptions {
methods: string[];
}
}
declare function e(
getter?: string | ((req: express.Request, res: express.Response) => string),
options?: e.MethodOverrideOptions,
): express.RequestHandler;
export = e;
These definitions were written by Santi Albo.
FAQs
TypeScript definitions for method-override
The npm package @types/method-override receives a total of 290,330 weekly downloads. As such, @types/method-override popularity was classified as popular.
We found that @types/method-override demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.