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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-connect-api-mocker

v0.0.16

Published

Create a mock API server using Vite and Connect

Downloads

1,001

Readme

Vite Connect API Mocker

It’s a Vite plugin that implements Node.js and Connect to create a middleware that simulates API responses. It is particularly useful for mocking APIs in SPA applications.

Requirements

  • vite >= 4.0.0
  • esbuild >= 0.17

Installation

npm install vite-connect-api-mocker --save-dev

Usage

  • Creation folder mocks in root project
  • Creation folder api in mocks folder
  • Creation folder product in api folder
  • Creation file POST.json in product folder
import {
  connectApiMocker,
  HttpMethods,
  HttpStatus,
  HttpContentType,
} from 'vite-connect-api-mocker'
import fs from 'fs/promises'

export default defineConfig({
  plugins: [
    connectApiMocker({
      mocks: [
        {
          url: '/api/product',
          method: HttpMethods.POST,
          timeout: 2000,
          statusCode: HttpStatus.CREATED,
          contentType: HttpContentType.JSON,
          response: async (req, res) => {
            const response = await fs.readFile(
              './mocks/api/product/POST.json',
              'utf-8',
            )
            res.end(response)
          },
        },
      ],
    }),
  ],
})

Available Enumerations

HttpStatus

This enumeration provides standard HTTP status codes that you can use to simulate API responses.

import { HttpStatus } from 'vite-connect-api-mocker';

console.log(HttpStatus.CREATED); // 201
console.log(HttpStatus.BAD_REQUEST); // 400

| Code | Name | Description | |------|--------------------------------|------------------------------------------------------| | 201 | CREATED | The request was successful and a resource was created. | | 200 | OK | The request was successful. | | 400 | BAD_REQUEST | The request is invalid. | | 401 | UNAUTHORIZED | The client is not authorized. | | 403 | FORBIDDEN | The client does not have permission to perform this.| | 404 | NOT_FOUND | The requested resource does not exist. | | 409 | CONFLICT | Conflict with the current state of the resource. | | 500 | INTERNAL_SERVER_ERROR | Internal server error. | | 503 | SERVICE_UNAVAILABLE | The service is unavailable. | | 504 | GATEWAY_TIMEOUT | The server did not respond in time. | | 502 | BAD_GATEWAY | Gateway or proxy error. | | 422 | UNPROCESSABLE_ENTITY | Unprocessable entity. | | 429 | TOO_MANY_REQUESTS | Too many requests in a short period of time. | | 413 | PAYLOAD_TOO_LARGE | Payload is too large. | | 451 | UNAVAILABLE_FOR_LEGAL_REASONS | Unavailable due to legal reasons. | | 511 | NETWORK_AUTHENTICATION_REQUIRED | Network authentication is required. | | 599 | NETWORK_CONNECT_TIMEOUT_ERROR | Network connection timeout occurred. |


HttpMethods

This enum lists the standard HTTP methods you can use when interacting with a mock API.

import { HttpMethods } from 'vite-connect-api-mocker';

console.log(HttpMethods.POST); // 'POST'
console.log(HttpMethods.GET); // 'GET'

| Method | Description | |----------|----------------------------------------------| | POST | Sends data to create a resource. | | GET | Retrieves data from the server. | | PUT | Updates or creates a full resource. | | DELETE | Deletes an existing resource. | | PATCH | Partially updates an existing resource. |


HttpContentType

This enum defines the most common content types you can use in HTTP requests or responses.

import { HttpContentType } from 'vite-connect-api-mocker';

console.log(HttpContentType.JSON); // 'application/json'
console.log(HttpContentType.HTML); // 'text/html'

| Type | Value | Description | |---------------------------|------------------------------|--------------------------------------------| | JSON | application/json | JSON data format. | | TEXT | text/plain | Plain text. | | HTML | text/html | HTML document. | | XML | application/xml | XML data format. | | PDF | application/pdf | PDF file. | | IMAGE | image/jpeg | JPEG image. | | VIDEO | video/mp4 | MP4 video. | | AUDIO | audio/mpeg | MPEG audio. |