0.2.0 • Published 1 year ago

@neoncitylights/typed-http v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@neoncitylights/typed-http

License: MIT GitHub deployments Node.js workflow npm (scoped)

A TypeScript package that provides strongly typed HTTP header names. Supports the Fetch API, XmlHttpRequest, and the Node.js HTTP module with zero-runtime overhead.

This package uses an open-source JSON dataset by WebConcepts with slight modifications, available under concepts.json. The script to auto-generate the TypeScript files is available under generateHttpTypes.ts. The generated files are:

Install

npm install @neoncitylights/typed-http

Documentation

Auto-generated API documentation is available.

API Reference

Note: Specific HTTP headers, methods, and status codes are omitted from the API documentation for brevity. The full list of types is available in the source code.

  • T: # headers.HttpHeadersource
  • T: # headers.HttpRequestHeadersource
  • T: # headers.HttpResponseHeadersource
  • T: # headers.ForbiddenHttpRequestHeadersource
  • T: # headers.ForbiddenHttpResponseHeadersource
  • T: # methods.HttpMethodsource
  • T: # statusCodes.HttpStatusCodesource
  • T: # statusCodes.HttpInfoStatusCodesource
  • T: # statusCodes.HttpSuccessStatusCodesource
  • T: # statusCodes.HttpRedirectStatusCodesource
  • T: # statusCodes.HttpClientErrorStatusCodesource
  • T: # statusCodes.HttpServerErrorStatusCodesource

Usage

Type the Fetch API

import '@neoncitylights/typed-http/fetch';

let request = await fetch();

Type XmlHttpRequest

import '@neoncitylights/typed-http/xhr';

const xhr = new XMLHttpRequest();
xhr.addEventListener('load', (e) => console.log(xhr.responseText));
xhr.open('GET', 'https://www.google.com');
xhr.send();

Type the Node.js HTTP module

import '@neoncitylights/typed-http/node';

License

This library is licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.