express-allow-methods
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

express-allow-methods

Express middleware for sending HTTP 405 Method Not Allowed response. Due to the specification requirements, it also responds with the Allow header with comma-separated list of allowed methods.

Package demo using cUrl terminal command

Prerequisites

  • Node.JS v0.11.8+
  • (optionally) TypeScript v3.8.2+

Installation

npm i express-allow-methods

# can be skipped for non-TypeScript projects
npm i --save-dev typescript

In a TypeScript file:

import allowMethods from "express-allow-methods";

In a JavaScript (CommonJS) file:

const allowMethods = require("express-allow-methods").default;

Usage

import express from "express";
import allowMethods from "express-allow-methods";

const app = express();

app.route("/")
	.all(allowMethods("GET", "POST"))
	.get((req, res) => {
		// GET /
	})
	.post((req, res) => {
		// POST /
	})
	.patch((req, res) => {
		// PATCH /
		// the code here will never run
	});

/express-allow-methods/

    Package Sidebar

    Install

    npm i express-allow-methods

    Weekly Downloads

    0

    Version

    0.3.1

    License

    MIT

    Unpacked Size

    12.2 kB

    Total Files

    12

    Last publish

    Collaborators

    • parzhitsky