Skip to content

Latest commit

 

History

History

http-types

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@neoncitylights/http-types

License: MIT npm (scoped)

A pure TypeScript package that provides strongly typed HTTP headers, methods, and status codes. 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/http-types

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/http-types/fetch';

let request = await fetch();

Type XmlHttpRequest

import '@neoncitylights/http-types/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/http-types/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.