Scalar Mock Server
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'
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',
},
},
},
},
},
},
},
},
}
const app = await createMockServer({
specification,
onRequest({ context, operation }) {
console.log(context.req.method, context.req.path)
},
})
serve(
{
fetch: app.fetch,
port: 3000,
},
(info) => {
console.log(`Listening on http://localhost:${info.port}`)
},
)
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.