http-method-constants
v1.0.1-beta.0
Published
Type-safe HTTP method constants for TypeScript
Downloads
3
Maintainers
Readme
http-method-constants
A comprehensive but lightweight, type-safe HTTP method constants library for TypeScript projects. Includes all standard HTTP methods from RFC 7231, RFC 5789, and RFC 4918 (WebDAV).
Installation
npm install http-method-constants
Usage
import {
HttpMethod,
HTTP_METHODS,
isHttpMethod,
isSafeMethod,
isIdempotentMethod,
isCacheableMethod,
isWebDAVMethod,
} from 'http-method-constants';
// Using enum
const method = HttpMethod.GET;
// Using constant object
const postMethod = HTTP_METHODS.POST;
// Using type checking
if (isHttpMethod(someString)) {
// someString is now typed as HttpMethodString
}
// Check method properties
console.log(isSafeMethod('GET')); // true
console.log(isIdempotentMethod('PUT')); // true
console.log(isCacheableMethod('POST')); // true
console.log(isWebDAVMethod('PROPFIND')); // true
// Access method groups
import {
SAFE_METHODS,
IDEMPOTENT_METHODS,
CACHEABLE_METHODS,
WEBDAV_METHODS,
} from 'http-method-constants';
console.log(SAFE_METHODS); // ['GET', 'HEAD', 'OPTIONS', 'TRACE']
Features
- Complete set of HTTP methods from RFC 7231, RFC 5789, and RFC 4918
- TypeScript support with type safety
- Multiple formats: enum, constant object, and array
- Method categorization (Safe, Idempotent, Cacheable, WebDAV)
- Type guard functions for all categories
- Zero dependencies
- Comprehensive tests
Included HTTP Methods
Standard Methods:
- GET, HEAD, POST, PUT, DELETE
- CONNECT, OPTIONS, TRACE, PATCH
Extended Methods:
- MERGE, COPY, MOVE
- LOCK, UNLOCK
- MKCOL, PROPFIND, PROPPATCH
- SEARCH, PURGE
- LINK, UNLINK
Method Categories
The package includes predefined groups of methods based on their properties:
- Safe Methods: Methods that don't modify resources
- Idempotent Methods: Methods that produce the same result when called multiple times
- Cacheable Methods: Methods whose responses can be cached
- WebDAV Methods: Methods specific to WebDAV protocol
Contributing and Publishing
Initial Setup
Clone the repository:
git clone https://github.com/yourusername/http-method-constants.git cd http-method-constants
Install dependencies:
npm install
Set up npm authentication:
npm login
Publishing a New Version
Quick Publish
For straightforward version bumps, use one of these commands:
# For patch version (1.0.0 -> 1.0.1)
npm run publish:patch
# For minor version (1.0.0 -> 1.1.0)
npm run publish:minor
# For major version (1.0.0 -> 2.0.0)
npm run publish:major
# For beta releases (1.0.0 -> 1.0.1-beta.0)
npm run publish:beta
These commands will:
- Run all tests
- Bump the version in package.json
- Create a git commit and tag
- Push to GitHub, triggering automatic npm publication
Publishing with Release Notes
For releases with detailed notes:
Create and push your changes:
git add . git commit -m "feat: your changes"
Create a new version with a message:
# Format: npm version [patch|minor|major] -m "Release %s - your message" npm version patch -m "Release %s - Added new HTTP methods"
Push with tags:
git push --follow-tags
[Optional] Add detailed release notes:
- Go to GitHub repository
- Navigate to "Releases"
- Click on the tag that was just created
- Click "Edit tag"
- Add your detailed release notes with Markdown formatting
- Publish release
Version Guidelines
patch
(1.0.0 -> 1.0.1): Bug fixes and minor changesminor
(1.0.0 -> 1.1.0): New features, backward compatiblemajor
(1.0.0 -> 2.0.0): Breaking changesbeta
(1.0.0 -> 1.0.1-beta.0): Pre-release versions
Troubleshooting
If the automatic publish fails:
- Check GitHub Actions for error details
- Verify your NPM_TOKEN is set correctly in GitHub Secrets
- Ensure the package name is available on npm
- Check if version exists already on npm
For manual publishing (if needed):
npm run build
npm test
npm publish
Beta Releases
For testing before a main release:
npm run publish:beta
# Installs as: npm install http-method-constants@beta
License
MIT