@scalar/mock-server
TypeScript icon, indicating that this package has built-in type declarations

0.1.71 • Public • Published

Scalar Mock Server

A server returning fake data based on an OpenAPI specification

Installation

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}`)
  },
)

/@scalar/mock-server/

    Package Sidebar

    Install

    npm i @scalar/mock-server

    Weekly Downloads

    637

    Version

    0.1.71

    License

    MIT

    Unpacked Size

    42.2 kB

    Total Files

    9

    Last publish

    Collaborators

    • amritkahlon
    • scalar_geoff
    • mason-little
    • hwkr
    • tommastro
    • cameronrohani
    • hanspagel
    • marclave