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

@corefunc/http

v1.0.8

Published

Utilities and tools to help build HTTP requests

Downloads

194

Readme

CoreFunc

CoreFunc HTTP

Utilities and tools to help build HTTP requests.

NPM Version NPM Downloads GitHub Stars TypeScript Typings Travis CI LGTM


Usage

import {
  HTTP_HEADER,
  STATUS_CODE_EMPTY, STATUS_CODE_TEXT,
  httpResponseJson, httpStatusText,
} from "@corefunc/http";

AMD, UMD, browser script tag.

<script src="https://unpkg.com/@corefunc/http"></script>

CDN (unpkg https://unpkg.com/)

<script src="https://unpkg.com/@corefunc/http" type="module"></script>

Deno (Pika https://pika.dev/)

import {
  HTTP_HEADER,
  STATUS_CODE_EMPTY, STATUS_CODE_TEXT,
  httpResponseJson, httpStatusText,
} from "https://cdn.pika.dev/@corefunc/http";

Examples

httpResponseJson(200);
// '{"message":"OK","statusCode":200}'
httpResponseJson("200");
// '{"message":"OK","statusCode":200}'
httpResponseJson`200`;
// '{"message":"OK","statusCode":200}'
httpResponseJson(403, "Not for you");
// '{"error":true,"message":"Not for you","statusCode":403}'
httpResponseJson`403 Not for you`;
// '{"error":true,"message":"Not for you","statusCode":403}'
httpResponseJson(500, { errorForDeveloper: "", errorForUser: "" });
// '{"message":"Internal Server Error","statusCode":500,"errorForDeveloper":"","errorForUser":"","error":true}'

API

import { OK /* 200 */, CREATED /* 201 */ } from "@corefunc/http";
const HTTP_HEADER: { [key: string]: string };
// HTTP_HEADER.CONTENT_LENGTH -> "Content-Length"
const HTTP_MEDIA_TYPE: { [key: string]: string };
// HTTP_MEDIA_TYPE.IMAGE_WEBP -> "image/webp"
const HTTP_METHOD: { [key: string]: string };
// HTTP_METHOD.POST -> "POST"
const STATUS_CODE_EMPTY: number[];
// [ 204, 205, 304 ]
const STATUS_CODE_REDIRECT: number[];
// [300, 301, 302, 303, 305, 307, 308]
const STATUS_CODE_RETRY: number[];
// [502, 503, 504]
const STATUS_CODE_MEMO: { [key: string]: string };
// STATUS_CODE_MEMO.ACCEPTED -> "Accepted"
const STATUS_CODE_TAG: { [key: string]: number };
// STATUS_CODE_TAG.FORBIDDEN -> 403
const STATUS_CODE_TEXT: { [key: string]: string };
// STATUS_CODE_TEXT["202"] -> "Accepted"
function httpResponse(code: number | string, message?: string | object): { [key: string]: any; };
// httpResponse(202) -> { message: 'Accepted', statusCode: 202 }
function httpResponseHtml(code: number | string, message?: string | object): string;
function httpResponseJson(code: number | string, message?: string | object): string;
// httpResponseJson(202) -> {"message":"Accepted","statusCode":202}
function httpResponseText(code: number | string, message?: string | object): string;
function httpResponseXml(code: number | string, message?: string | object): string;
function httpStatusCode(code: number | string): number;
// httpStatusCode("404") -> 404
function httpStatusText(code: number | string): string;
// httpStatusText(404) -> "Not Found"

Cheatsheet

1XX

100 CONTINUE
101 SWITCHING_PROTOCOLS
102 PROCESSING
103 EARLY_HINTS

2XX

200 OK
201 CREATED
202 ACCEPTED
203 NON_AUTHORITATIVE_INFORMATION
204 NO_CONTENT
205 RESET_CONTENT
206 PARTIAL_CONTENT
207 MULTI_STATUS
208 ALREADY_REPORTED
226 IM_USED

3XX

300 MULTIPLE_CHOICES
301 MOVED_PERMANENTLY
302 MOVED_TEMPORARILY
303 SEE_OTHER
304 NOT_MODIFIED
305 USE_PROXY
306 UNUSED
307 TEMPORARY_REDIRECT
308 PERMANENT_REDIRECT

4XX

400 BAD_REQUEST
401 UNAUTHORIZED
402 PAYMENT_REQUIRED
403 FORBIDDEN
404 NOT_FOUND
405 METHOD_NOT_ALLOWED
406 NOT_ACCEPTABLE
407 PROXY_AUTHENTICATION_REQUIRED
408 REQUEST_TIMEOUT
409 CONFLICT
410 GONE
411 LENGTH_REQUIRED
412 PRECONDITION_FAILED
413 PAYLOAD_TOO_LARGE
414 REQUEST_URI_TOO_LONG
415 UNSUPPORTED_MEDIA_TYPE
416 REQUESTED_RANGE_NOT_SATISFIABLE
417 EXPECTATION_FAILED
418 IM_A_TEAPOT
419 INSUFFICIENT_SPACE_ON_RESOURCE
420 ENHANCE_YOUR_CALM
421 MISDIRECTED_REQUEST
422 UNPROCESSABLE_ENTITY
423 LOCKED
424 FAILED_DEPENDENCY
425 TOO_EARLY
426 UPGRADE_REQUIRED
428 PRECONDITION_REQUIRED
429 TOO_MANY_REQUESTS
430 WOULD_BLOCK
431 REQUEST_HEADER_FIELDS_TOO_LARGE
451 UNAVAILABLE_FOR_LEGAL_REASONS

5XX

500 INTERNAL_SERVER_ERROR
501 NOT_IMPLEMENTED
502 BAD_GATEWAY
503 SERVICE_UNAVAILABLE
504 GATEWAY_TIMEOUT
505 HTTP_VERSION_NOT_SUPPORTED
506 VARIANT_ALSO_NEGOTIATES
507 INSUFFICIENT_STORAGE
508 LOOP_DETECTED
509 BANDWIDTH_LIMIT_EXCEEDED
510 NOT_EXTENDED
511 NETWORK_AUTHENTICATION_REQUIRED

See also

My other projects