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

oc-test

v1.1.0

Published

Express.js middleware for rendering Bruno Playground - API documentation made easy

Readme

oc-test

Express.js middleware for rendering Bruno Playground - API documentation made easy with server-side rendering.

Features

  • 🚀 Express.js Integration: Seamless middleware and route handlers
  • 📚 Server-Side Rendering: Generate complete HTML with embedded playground
  • 🎨 Customizable Themes: Light, dark, and auto themes
  • 🔧 Easy Configuration: Simple object-based API collection format
  • 🛡️ Security: XSS protection and safe HTML generation
  • 📱 Responsive: Mobile-friendly API documentation
  • CDN Ready: Uses CDN-hosted assets for fast loading

Installation

npm install oc-test

Quick Start

const express = require('express');
const { playgroundHandler } = require('oc-test');

const app = express();

// Simple route handler
app.get('/api-docs', playgroundHandler({
  name: "My API",
  description: "My awesome API documentation",
  items: [{
    type: "http",
    method: "GET",
    url: "https://api.example.com/users",
    docs: "Get all users"
  }]
}));

app.listen(3000, () => {
  console.log('API docs available at http://localhost:3000/api-docs');
});

Usage Examples

1. Route Handler (Recommended)

const { playgroundHandler } = require('oc-test');

const githubAPI = {
  name: "GitHub API",
  description: "GitHub REST API endpoints",
  environments: [{
    name: "production",
    variables: [{
      name: "baseUrl",
      value: "https://api.github.com"
    }]
  }],
  items: [{
    type: "http",
    method: "GET", 
    url: "{{baseUrl}}/user",
    headers: [{
      name: "Authorization",
      value: "token YOUR_TOKEN"
    }],
    docs: "Get authenticated user"
  }]
};

app.get('/github', playgroundHandler(githubAPI, {
  title: "GitHub API Documentation",
  theme: "dark"
}));

2. Middleware Pattern

const { createPlaygroundMiddleware } = require('oc-test');

// Global middleware with default options
app.use(createPlaygroundMiddleware({
  theme: 'auto',
  logo: 'https://example.com/logo.png'
}));

app.get('/api-docs', (req, res) => {
  res.playground({
    name: "My API",
    items: [
      // your API endpoints
    ]
  }, {
    title: "Custom API Docs"
  });
});

3. Direct Rendering

const { renderPlayground } = require('oc-test');

app.get('/custom', (req, res) => {
  const html = renderPlayground({
    opencollection: {
      name: "Custom API",
      items: [{
        method: "POST",
        url: "/api/users",
        body: {
          name: "John Doe",
          email: "[email protected]"
        }
      }]
    },
    theme: "light",
    title: "Custom Documentation"
  });
  
  res.send(html);
});

API Reference

playgroundHandler(collection, options?)

Creates an Express route handler.

Parameters:

  • collection (Object): Your API collection in OpenCollection format
  • options (Object, optional): Playground configuration options

Returns: Express route handler function

createPlaygroundMiddleware(defaultOptions?)

Creates Express middleware that adds res.playground() method.

Parameters:

  • defaultOptions (Object, optional): Default options for all playgrounds

Returns: Express middleware function

renderPlayground(options)

Renders playground HTML directly.

Parameters:

  • options (Object): Complete playground configuration

Returns: HTML string

convertObjectToBruno(collection)

Converts OpenCollection format to Bruno format.

Parameters:

  • collection (Object): OpenCollection format

Returns: Bruno collection object

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | opencollection | Object | Required | Your API collection | | title | String | "API Playground" | Page title | | theme | String | "auto" | Theme: "light", "dark", or "auto" | | logo | String | undefined | URL to your logo image | | hideSidebar | Boolean | false | Hide the sidebar navigation | | hideHeader | Boolean | false | Hide the header | | cdnUrl | String | CDN URL | Custom URL for playground assets |

OpenCollection Format

Define your API using this simple format:

{
  name: "API Name",
  description: "API description", 
  environments: [{
    name: "production",
    variables: [{
      name: "baseUrl",
      value: "https://api.example.com"
    }]
  }],
  items: [{
    type: "http",
    method: "GET",
    url: "{{baseUrl}}/endpoint",
    headers: [{
      name: "Authorization", 
      value: "Bearer {{token}}"
    }],
    params: [{
      name: "limit",
      value: "10",
      type: "query"
    }],
    body: {
      name: "example",
      value: "data"
    },
    docs: "Endpoint description"
  }],
  docs: "# API Documentation\n\nOverall API documentation here."
}

Complete Example

const express = require('express');
const { playgroundHandler, createPlaygroundMiddleware } = require('oc-test');

const app = express();

// Middleware approach
app.use(createPlaygroundMiddleware({
  theme: 'auto',
  logo: 'https://example.com/logo.png'
}));

// Multiple API documentations
const apis = {
  github: {
    name: "GitHub API",
    description: "GitHub REST API v3",
    environments: [{
      name: "production", 
      variables: [{ name: "baseUrl", value: "https://api.github.com" }]
    }],
    items: [{
      method: "GET",
      url: "{{baseUrl}}/user",
      headers: [{ name: "Authorization", value: "token YOUR_TOKEN" }],
      docs: "Get authenticated user"
    }]
  },
  
  stripe: {
    name: "Stripe API",
    description: "Stripe payment processing",
    items: [{
      method: "GET", 
      url: "https://api.stripe.com/v1/customers",
      headers: [{ name: "Authorization", value: "Bearer sk_test_..." }],
      docs: "List customers"
    }]
  }
};

// Route handlers
app.get('/', (req, res) => {
  res.send(`
    <h1>API Documentation</h1>
    <ul>
      <li><a href="/github">GitHub API</a></li>
      <li><a href="/stripe">Stripe API</a></li>
      <li><a href="/custom">Custom API</a></li>
    </ul>
  `);
});

app.get('/github', playgroundHandler(apis.github, { theme: 'dark' }));
app.get('/stripe', playgroundHandler(apis.stripe, { theme: 'light' }));

app.get('/custom', (req, res) => {
  res.playground({
    name: "Custom API",
    items: [{ method: "GET", url: "/api/test" }]
  });
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`🚀 Server running on http://localhost:${PORT}`);
  console.log(`📖 API docs:`);
  console.log(`   • GitHub: http://localhost:${PORT}/github`);
  console.log(`   • Stripe: http://localhost:${PORT}/stripe`);
  console.log(`   • Custom: http://localhost:${PORT}/custom`);
});

TypeScript Support

Full TypeScript definitions are included:

import { playgroundHandler, OpenCollection } from 'oc-test';

const collection: OpenCollection = {
  name: "My API",
  items: [{
    type: "http",
    method: "GET",
    url: "https://api.example.com"
  }]
};

app.get('/docs', playgroundHandler(collection));

License

MIT

Contributing

Issues and pull requests welcome! Visit the GitHub repository for more information.