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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@denis_bruns/http-middleware

v0.1.0

Published

> **A modular middleware library for HTTP client requests.** > This package provides middleware to inject secrets from AWS Secrets Manager and environment variables into HTTP request options, and a factory to chain multiple middleware Observables togeth

Readme

@denis_bruns/http-middleware

A modular middleware library for HTTP client requests.
This package provides middleware to inject secrets from AWS Secrets Manager and environment variables into HTTP request options, and a factory to chain multiple middleware Observables together.

NPM Version
TypeScript
License: MIT
GitHub


Overview

@denis_bruns/http-middleware supplies three key pieces of functionality:

  1. AWS Secrets Manager Middleware
    Retrieves secrets from AWS Secrets Manager (with caching) and injects them into HTTP request headers.

  2. Environment Variable Middleware
    Reads specified environment variables, caches their values for a configurable TTL, and injects them into HTTP request headers.

  3. HTTP Client Middleware Factory
    Composes multiple middleware Observables sequentially, merging their resulting configuration objects—allowing you to layer modifications to your HTTP client request options.

These middleware utilities are designed to work with a common HTTP client interface and help keep your application configuration declarative and testable.


Key Features

  • AWS Secrets Middleware:

    • Uses @aws-sdk/client-secrets-manager to fetch secrets.
    • Caches secrets for 1 hour to reduce AWS calls.
    • Applies header mappings from secret keys to request headers.
    • Throws a custom AWSSecretsManagerError if the secret string is absent.
  • Environment Middleware:

    • Reads environment variables using a provided mapping.
    • Caches variable values for 5 minutes.
    • Emits an EnvironmentError if a required variable is missing.
    • Synchronously sets headers using a custom Observable to catch errors.
  • Middleware Factory:

    • Sequentially chains multiple middleware Observables.
    • Merges headers and other configuration options step-by-step.
    • Enables a functional, modular approach to composing HTTP request configurations.

Installation

You can install the package using npm or yarn:

npm install @denis_bruns/http-middleware

Or with yarn:

yarn add @denis_bruns/http-middleware

Make sure you have the following peer dependencies installed:

  • TypeScript 5.x
  • rxjs
  • @aws-sdk/client-secrets-manager
  • @denis_bruns/core

Basic Usage

1. AWS Secrets Manager Middleware

This middleware fetches secrets from AWS Secrets Manager and appends header values.

import { createAwsSecretsMiddleware, AWSSecretsManagerError } from '@denis_bruns/http-middleware';
import { HttpClientRequestOptions, ISecretManagerConfig } from '@denis_bruns/core';
import { firstValueFrom } from 'rxjs';

const secretManagerConfig: ISecretManagerConfig = {
  region: 'us-east-1',
  secretName: 'my-secret',
  headerMappings: {
    'X-API-Key': 'API_KEY',
    'Authorization': 'AUTH_TOKEN',
  }
};

const requestOptions: HttpClientRequestOptions = {
  headers: { 'Content-Type': 'application/json' },
};

createAwsSecretsMiddleware(secretManagerConfig, requestOptions)
  .subscribe({
    next: (options) => {
      console.log('Updated request options:', options.headers);
    },
    error: (err: AWSSecretsManagerError) => {
      console.error('Failed to fetch secrets:', err.message);
    }
  });

2. Environment Variable Middleware

This middleware reads environment variables, applies caching, and sets headers accordingly.

import { createEnvironmentMiddleware, EnvironmentError } from '@denis_bruns/http-middleware';
import { HttpClientRequestOptions, EnvironmentVariable } from '@denis_bruns/core';
import { firstValueFrom } from 'rxjs';

const headerMappings = {
  'X-API-Key': 'API_KEY' as EnvironmentVariable,
};

const requestOptions: HttpClientRequestOptions = {
  headers: { 'Content-Type': 'application/json' },
};

firstValueFrom(createEnvironmentMiddleware(headerMappings, requestOptions))
  .then((options) => {
    console.log('Environment headers:', options.headers);
  })
  .catch((err: EnvironmentError) => {
    console.error('Environment variable missing:', err.message);
  });

3. HTTP Client Middleware Factory

The factory composes multiple middleware in order. Each middleware builds on the configuration produced by the previous one.

import { createHttpClientMiddlewareFactory } from '@denis_bruns/http-middleware';
import { HttpClientRequestOptions } from '@denis_bruns/core';
import { of, firstValueFrom } from 'rxjs';
import { map } from 'rxjs/operators';

const initialConfig: HttpClientRequestOptions = { headers: { 'Content-Type': 'application/json' } };

const middleware1$ = of(initialConfig).pipe(
  map((config) => ({
    ...config,
    headers: { ...config.headers, 'X-Test-1': 'value1' }
  }))
);

const middleware2$ = of(initialConfig).pipe(
  map((config) => ({
    ...config,
    headers: { ...config.headers, 'X-Test-2': 'value2' }
  }))
);

createHttpClientMiddlewareFactory([middleware1$, middleware2$], initialConfig)
  .subscribe((finalConfig) => {
    console.log('Final merged request options:', finalConfig.headers);
  });

// Expected output includes headers from both middlewares:
// { 'Content-Type': 'application/json', 'X-Test-1': 'value1', 'X-Test-2': 'value2' }

Related Packages

  • @denis_bruns/core
    NPM
    GitHub
    Provides core types and interfaces used for clean architecture and HTTP client configuration.

  • @denis_bruns/http-angular
    NPM

    • GitHub Angular HTTP Client conforming axios interfaces with middleware support
  • @denis_bruns/http-axios
    NPM

    • GitHub HTTP Client built on axios with middleware support

Contributing

Contributions, bug reports, and feature requests are always welcome.
Please open an issue or submit a pull request on GitHub.


License

This project is MIT licensed.