npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-method-constants

v1.0.1-beta.0

Published

Type-safe HTTP method constants for TypeScript

Downloads

68

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

  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