Skip to content

Utilities

Generates deterministic SHA-256 hashes for cache and deduplication keys.

import { hashRequest } from '@http-client-toolkit/core';
const hash = hashRequest('https://api.example.com/search', {
q: 'test',
page: 1,
});
  • Deterministic — Same URL + params always produces the same hash
  • Order-independent{ a: 1, b: 2 } and { b: 2, a: 1 } produce the same hash
  • Normalized primitives — Numbers and strings are normalized before hashing ("10" and 10, "true" and true produce the same hash)
  • Undefined omittedundefined values are omitted; null is preserved
  • Host-awareHttpClient hashes by URL origin + path + normalized query params, so identical paths on different hosts do not collide

Custom error class wrapping HTTP errors. Includes the HTTP status code when applicable.

import { HttpClientError } from '@http-client-toolkit/core';
PropertyTypeDescription
messagestringError description
statusCodenumber | undefinedHTTP status code (e.g. 404, 500)
try {
await client.get(url);
} catch (error) {
if (error instanceof HttpClientError) {
console.log(error.message); // "Not Found"
console.log(error.statusCode); // 404
}
}

The @http-client-toolkit/core package exports:

ExportTypeDescription
HttpClientClassMain client class
HttpClientErrorClassError class with statusCode
hashRequestFunctionDeterministic SHA-256 request hashing
CacheStoreInterfaceCache store contract
DedupeStoreInterfaceDeduplication store contract
RateLimitStoreInterfaceRate limit store contract
AdaptiveRateLimitStoreInterfaceAdaptive rate limit store contract