Registry / http-networking / http-methods-constants

http-methods-constants

JSON →
library1.1.0jsnpmunverified

http-methods-constants is a lightweight utility package that provides standard HTTP method verbs as string constants. Its primary purpose is to eliminate "magic strings" in codebases, improving readability and reducing potential typos when referring to methods like 'GET', 'POST', 'PUT', or 'DELETE'. The current stable version is 1.1.0. Given its fundamental nature, it is expected to have a very stable and infrequent release cadence, with new versions primarily occurring for minor improvements or ecosystem compatibility updates rather than new features. It differentiates itself through its extreme simplicity and singular focus, offering a straightforward object of string constants without additional logic or validation, making it an ideal drop-in for projects needing explicit HTTP method references.

npm install http-methods-constants
INSTALL
IMPORT
SIG · HTTP-METHODS-CONST
H
http-methods-constants
http-networkingjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

httpMethods
const httpMethods = require('http-methods-constants');
import { GET } from 'http-methods-constants';
The package exports a single default object containing all methods. Named imports are not supported.
httpMethods.GET
const httpMethods = require('http-methods-constants'); console.log(httpMethods.GET);
import httpMethods from 'http-methods-constants'; console.log(httpMethods['get']);
Method names are uppercase strings (e.g., 'GET'). Access them as properties of the imported object.
httpMethods (ESM)
import httpMethods from 'http-methods-constants';
import * as httpMethods from 'http-methods-constants';
While primarily a CommonJS module, modern bundlers and Node.js environments can import the default export as a module.

Demonstrates importing the constants object and iterating through all available HTTP methods, followed by a conceptual example of using them in a request handler for clarity.

const httpMethods = require('http-methods-constants'); console.log("All supported HTTP methods:"); for (const methodKey in httpMethods) { if (Object.prototype.hasOwnProperty.call(httpMethods, methodKey)) { console.log(`- ${methodKey}: ${httpMethods[methodKey]}`); } } // Example usage in an Express.js-like route handler (conceptual) function handleRequest(method, path, body) { if (method === httpMethods.GET && path === '/api/data') { console.log(`Handling GET request for ${path}`); return { status: 200, data: 'Some data' }; } else if (method === httpMethods.POST && path === '/api/items') { console.log(`Handling POST request for ${path} with body:`, body); return { status: 201, message: 'Item created' }; } return { status: 404, message: 'Not Found' }; } console.log(handleRequest('GET', '/api/data')); console.log(handleRequest('POST', '/api/items', { name: 'New Item' }));
Debug
Known issues
gotchaThis package only provides string constants for HTTP methods. It does not include any validation logic, parsing capabilities, or integration with HTTP servers/clients. It is purely for referencing method names.
fix
Use a dedicated HTTP framework (e.g., Express, Koa) or a request library (e.g., Axios, Node's built-in `http` module) for actual HTTP request handling and validation.
affects: >=1.0.0
gotchaThe package currently appears to be primarily a CommonJS module. While bundlers and Node.js can often handle `import httpMethods from 'http-methods-constants';` for CJS default exports, direct named ESM imports (e.g., `import { GET } from 'http-methods-constants';`) are not supported.
fix
Always import the full object: `const httpMethods = require('http-methods-constants');` for CommonJS or `import httpMethods from 'http-methods-constants';` for ESM.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'GET') or similar 'is not a function' errors
Incorrect import of the http-methods-constants module, often due to attempting named imports or failing to correctly assign the default export.
fix
Ensure you are importing the full object: `const httpMethods = require('http-methods-constants');` in CommonJS or `import httpMethods from 'http-methods-constants';` in ESM. Then access methods as properties: `httpMethods.GET`.
ERR_MODULE_NOT_FOUND or MODULE_NOT_FOUND
The package was not installed, or the import/require path is incorrect.
fix
Run `npm install http-methods-constants` to ensure the package is in your `node_modules` directory. Verify the import statement is `require('http-methods-constants')` or `import httpMethods from 'http-methods-constants'`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
http-methods-constants — npm install http-methods-constants · libregistry