Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scalar/mock-server

Package Overview
Dependencies
Maintainers
0
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scalar/mock-server

OpenAPI mock server server

  • 0.2.65
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
782
increased by29.04%
Maintainers
0
Weekly downloads
 
Created
Source

Scalar Mock Server

Version Downloads License Discord

A powerful Node.js server that generates and returns realistic mock data based on OpenAPI specifications. Ideal for API development, testing, and prototyping.

Features

  • Automatically creates endpoints from your OpenAPI/Swagger document
  • Generates realistic sample data matching your schema definitions
  • Supports Swagger 2.0, OpenAPI 3.0 and 3.1 specifications
  • Customizable response handling and data generation
  • Perfect for frontend development without an actual backend

Quickstart

It’s part of our Scalar CLI, you can boot it literllay in seconds:

npx @scalar/cli mock openapi.json --watch

Installation

For more advanced use cases or finer control over the mock server, you can use the package directly in your Node.js application:

npm install @scalar/mock-server

Usage

import { serve } from '@hono/node-server'
import { createMockServer } from '@scalar/mock-server'

// Your OpenAPI specification
const specification = {
  openapi: '3.1.0',
  info: {
    title: 'Hello World',
    version: '1.0.0',
  },
  paths: {
    '/foobar': {
      get: {
        responses: {
          '200': {
            description: 'OK',
            content: {
              'application/json': {
                example: {
                  foo: 'bar',
                },
              },
            },
          },
        },
      },
    },
  },
}

// Create the mocked routes
const app = await createMockServer({
  specification,
  onRequest({ context, operation }) {
    console.log(context.req.method, context.req.path)
  },
})

// Start the server
serve(
  {
    fetch: app.fetch,
    port: 3000,
  },
  (info) => {
    console.log(`Listening on http://localhost:${info.port}`)
  },
)

Community

We are API nerds. You too? Let’s chat on Discord: https://discord.gg/scalar

License

The source code in this repository is licensed under MIT.

Keywords

FAQs

Package last updated on 24 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc