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

extract-openapi-req

v1.0.3

Published

Extract OpenAPI metadata from HTTP requests

Downloads

3

Readme

extract-openapi-req

A lightweight TypeScript library for extracting OpenAPI metadata from HTTP requests. This package helps you easily extract and validate request metadata against your OpenAPI specifications.

Features

  • 🚀 Load OpenAPI specs from URL or object
  • 🔍 Extract OpenAPI metadata and path parameters
  • ✨ Match request paths against OpenAPI paths
  • 📘 Full TypeScript support
  • 🪶 Zero dependencies (except path-to-regexp)
  • 🔌 Framework agnostic design

Installation

npm install extract-openapi-req

Usage

import { OpenApiExtractor } from "extract-openapi-req";

// Initialize the extractor
const extractor = new OpenApiExtractor();

// Load spec from URL
await extractor.loadSpec("https://api.example.com/openapi.json");

// Or load from object
await extractor.loadSpec(require("./openapi.json"));

// Extract metadata from a request
const metadata = extractor.extract("/v1/users/123", "GET");

if (metadata) {
  console.log("Operation ID:", metadata.schema.operationId);
  console.log("Path Parameters:", metadata.params);
  console.log("Full Operation Schema:", metadata.schema);
}

Framework Integration Examples

Hono (Built-in Middleware)

import { Hono } from "hono";
import { OpenApiExtractor } from "extract-openapi-req";
import {
  createHonoMiddleware,
  HonoOpenApiVariables,
} from "extract-openapi-req/frameworks/hono";

const app = new Hono<{ Variables: HonoOpenApiVariables }>();
const extractor = new OpenApiExtractor();

// Load OpenAPI spec
await extractor.loadSpec(openApiSpec);

// Add the middleware
const middleware = createHonoMiddleware(extractor);
app.use("*", middleware);

// Access OpenAPI metadata in your handlers
app.get("/users/:id", (c) => {
  const metadata = c.get("openapi");
  // Use the metadata...
});

Express

import express from "express";
import { OpenApiExtractor } from "extract-openapi-req";

const app = express();
const extractor = new OpenApiExtractor();
await extractor.loadSpec("./openapi.json");

app.use((req, res, next) => {
  const metadata = extractor.extract(req.path, req.method);
  if (metadata) {
    req.openapi = metadata;
  }
  next();
});

API Reference

OpenApiExtractor

Methods

  • loadSpec(specOrUrl: string | object): Promise<void>
    Load an OpenAPI specification from a URL or object.

  • getSpec(): object | null
    Get the currently loaded OpenAPI specification.

  • extract(path: string, method: string): OpenApiRequestMetadata | null
    Extract OpenAPI metadata from a request path and method.

Framework Middlewares

Hono

  • createHonoMiddleware(extractor: OpenApiExtractor): MiddlewareHandler
    Creates a Hono middleware that automatically extracts and attaches OpenAPI metadata to the request context.

Types

interface OpenApiRequestMetadata {
  schema: OpenAPIV3.OperationObject; // Full OpenAPI operation object
  params: Record<string, string>; // Extracted path parameters
}

type HonoOpenApiVariables = {
  openapi: OpenApiRequestMetadata;
};

Roadmap

Check out our roadmap for upcoming features:

  • OpenAPI 2.0 & 3.1.x support
  • More prebuilt framework middlewares (Express, Fastify, etc.)
  • Better error messages and debugging
  • Request/Response validation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © ahmedrowaihi