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

@mokup/client

v2.0.0

Published

Client-side request switching and adapters for mokup.

Readme

@mokup/client

Client-side request switching utilities and adapters for Mokup.

Requirements

  • Node.js >=22.12.0

Upgrade notes

Install

pnpm add @mokup/client

Quick start (fetch)

import { createFetchAdapter, createMockResolver } from '@mokup/client'

const resolver = createMockResolver({
  mockBase: 'http://localhost:3300',
  realBase: 'https://api.example.com',
  pathMap: [{ from: '/api/*', to: '/*' }],
  markers: { header: true },
})

const mokupFetch = createFetchAdapter({ resolver })

await mokupFetch('/api/users', { mock: true })

mokupFetch also accepts a native Request. Its standard init overrides follow new Request(request, init), including body and signal inheritance. When the resolver keeps the URL unchanged, the adapter forwards the effective request so native streaming, keepalive, and redirect behavior are preserved.

When the resolver changes a Request URL (including query markers), the adapter buffers its body before sending it. This preserves binary and FormData payloads, their content type, keepalive, and body replay for 307/308 redirects. Cancellation also interrupts buffering. Use finite bodies on this path; for streaming uploads, pass a string or URL with init.body and the options required by your Fetch implementation. That path passes the body through directly and retains native streaming and redirect restrictions.

Quick start (axios)

import { applyMokupToAxios } from '@mokup/client'
import axios from 'axios'

const api = axios.create({ baseURL: 'https://api.example.com' })

applyMokupToAxios(api, {
  resolverOptions: {
    mockBase: 'http://localhost:3300',
    realBase: 'https://api.example.com',
    pathMap: [{ from: '/api/*', to: '/*' }],
  },
})

await api.request({ url: '/api/users', mock: true })

The adapter combines baseURL and url using Axios rules before applying the resolver. For example, baseURL: 'https://api.example.com/api/v1' with either url: 'users' or url: '/users' produces /api/v1/users. Absolute and protocol-relative URLs bypass baseURL unless allowAbsoluteUrls is false. Changes to api.defaults.baseURL and api.defaults.allowAbsoluteUrls take effect on subsequent requests. Resolver options can then rewrite the combined URL.

Resolver options

  • mockBase: mock server origin or base path
  • realBase: real API origin or base path
  • pathMap: prefix rewrite rules (/api/* -> /*)
  • allowHosts: only rewrite matching hosts, including protocol-relative URLs (//api.example.com/users)
  • markers: inject headers or query markers (x-mokup, __mokup)
  • storage: persist global toggle (optional)

Overrides and priority

Order (highest to lowest):

  1. Request mock or meta.mokup
  2. Headers/cookie/query markers
  3. Global setUseMock
  4. resolverOptions.env.useMock

Global switch

const resolver = createMockResolver({ mockBase, realBase })
resolver.setUseMock(true)

const useMock = resolver.getUseMock()