@neoncitylights/typed-http
v0.2.0
Published
Provides strongly typed HTTP header names. Supports the Fetch API, XmlHttpRequest, and the Node.js HTTP module with zero-runtime overhead.
Downloads
4
Maintainers
Readme
@neoncitylights/typed-http
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:
httpHeaders.ts
: 248 HTTP header typeshttpMethods.ts
: 40 HTTP method typeshttpStatusCodes.ts
: 63 HTTP status code types
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.HttpHeader • sourceT
: # headers.HttpRequestHeader • sourceT
: # headers.HttpResponseHeader • sourceT
: # headers.ForbiddenHttpRequestHeader • sourceT
: # headers.ForbiddenHttpResponseHeader • sourceT
: # methods.HttpMethod • sourceT
: # statusCodes.HttpStatusCode • sourceT
: # statusCodes.HttpInfoStatusCode • sourceT
: # statusCodes.HttpSuccessStatusCode • sourceT
: # statusCodes.HttpRedirectStatusCode • sourceT
: # statusCodes.HttpClientErrorStatusCode • sourceT
: # statusCodes.HttpServerErrorStatusCode • source
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.