1.0.1-beta.0 • Published 9 months ago

http-method-constants v1.0.1-beta.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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

  1. Clone the repository:

    git clone https://github.com/yourusername/http-method-constants.git
    cd http-method-constants
  2. Install dependencies:

    npm install
  3. 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: 1. Run all tests 2. Bump the version in package.json 3. Create a git commit and tag 4. Push to GitHub, triggering automatic npm publication

Publishing with Release Notes

For releases with detailed notes:

  1. Create and push your changes:

    git add .
    git commit -m "feat: your changes"
  2. 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"
  3. Push with tags:

    git push --follow-tags
  4. 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 changes
  • minor (1.0.0 -> 1.1.0): New features, backward compatible
  • major (1.0.0 -> 2.0.0): Breaking changes
  • beta (1.0.0 -> 1.0.1-beta.0): Pre-release versions

Troubleshooting

If the automatic publish fails: 1. Check GitHub Actions for error details 2. Verify your NPM_TOKEN is set correctly in GitHub Secrets 3. Ensure the package name is available on npm 4. 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

1.0.1-beta.0

9 months ago