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

@quilted/http

v0.3.0

Published

Provides a collection of HTTP-related types and utilities.

Downloads

188

Readme

@quilted/http

This library provides a collection of HTTP-related types and utilities.

Getting the library

Note: @quilted/quilt/http and @quilted/react-http re-export all of the types from this library. If you already have either @quilted/quilt or @quilted/react-http, you can use the exports from those libraries instead of @quilted/http.

Install this library as a dependency by running the following command:

yarn add @quilted/http

Using the library

This library provides the following helper types, which each represent some aspect of interacting with HTTP:

  • HttpMethod, an enum representing the allowed HTTP methods
  • StatusCode, an enum representing the standard response status codes
  • ResponseType, an enum representing the standard response status code classes
  • ReadonlyHeaders, which is a subset of the Headers type that represents headers that can’t be mutated (like those on some Request objects).
  • Cookies, ReadonlyCookies, and CookieOptions, a set of interfaces that provide an isomorphic pattern for getting and setting cookies
  • ContentSecurityPolicyDirective, ContentSecurityPolicySandboxAllow, and ContentSecurityPolicySpecialSource, enums that provide friendly names for creating a content security policy
  • PermissionsPolicyDirective and PermissionsPolicySpecialSource, enums that provide friendly names for creating a permissions policy

Using this library as types

Many of the types in this library are provided as enums. Enums are convenient for developers, because they let you avoid having plain strings or numbers all over the codebase; that is, many developers prefer:

import {StatusCode} from '@quilted/http';

const statusCode = StatusCode.NotFound;

Over:

const statusCode = 404;

While enums are convenient, they have a runtime cost, because the whole enum is included in the output bundles even if only a single enum value is used. For this reason, we recommend any library that uses @quilted/http use type imports to reference the enums in this package:

import type {StatusCode} from '@quilted/http';
// instead of
// import {StatusCode} from '@quilted/http';

export function myFunctionThatUsesStatusCode(code: StatusCode) {}

This allows consumers of your library to get type safety on the allowed values, but without forcing consumers to include the entire enum in their bundle if they’d prefer to use these types exclusively as types.

import {StatusCode} from '@quilted/http';

// Works when using the enum...
myFunctionThatUsesStatusCode(StatusCode.NotFound);

// And when using static values:
myFunctionThatUsesStatusCode(404);