Software DevelopmentGPTClaudeGemini

API Mock Server Generator Prompt

Use case: Quickly generate a functional API mock server for frontend development and testing based on OpenAPI specifications.

20 copies230 views323 wordsCreated Jul 27, 2026
VERIFIED SEO TEMPLATE
WHAT THIS PROMPT DOES
  • Designed to solve: Quickly generate a functional API mock server for frontend development and testing based on OpenAPI specifications.
  • Recommended engine compatibility: Runs best on GPT or Claude or Gemini
  • Structure layout: Incorporates 1 custom input variable fields
  • Execution output target: Generates structured markdown lists and blocks

PROMPT SOURCE CODE

You are an expert backend developer and API design specialist. Your task is to convert the provided OpenAPI 3.0 specification into a fully functional mock server using Node.js/Express. The server must respond with realistic, randomized valid data and include common error responses (e.g., 400, 404, 500) based on the spec.

<context>
OpenAPI spec:
{{openapi_spec}}
</context>

<rules>
1. Parse the OpenAPI spec and extract all paths, methods, parameters, request bodies, and response schemas.
2. Generate a single `server.js` file that sets up an Express app listening on port 3000.
3. For each operation, create a route handler that:
   - Validates required query/header parameters (if present) and returns a 400 error if missing.
   - Returns a random example from the response schema's `example` field or a generated object matching the schema.
   - Also has a random chance (e.g., 10%) to return an error response (400, 404, or 500) with appropriate message.
4. Use `faker` (or simple random generation) to produce realistic data for strings, numbers, dates, etc.
5. Output only the complete code inside a single markdown code block. Do not include any explanation or comments outside the block.
6. Use `express` and `cors` packages. Include a `package.json` with dependencies.
7. The server must handle CORS.
</rules>

<thinking>
First, I will analyze the OpenAPI spec to understand the endpoints and schemas. Then, I will design the Express routes, implementing random data generation and error simulation. I will ensure the code is clean, production-ready, and follows best practices.
</thinking>

CRITICAL RULES & NEGATIVE CONSTRAINTS:
- Do NOT include any explanatory text before or after the code block.
- Do NOT use real database or external services; all data must be generated in-memory.
- Do NOT use deprecated Express patterns.
- Banned words: "TODO", "FIXME", "placeholder".
- The output must be only a JSON object with keys: "code" (the server.js content) and "package" (the package.json content).

Strict output format:
```json
{
  "code": "...",
  "package": "..."
}
```

This prompt has 1 variable(s):

EXAMPLE OUTPUT

{ "code": "const express = require('express');\nconst cors = require('cors');\nconst app = express();\napp.use(cors());\napp.use(express.json());\n\nconst randomItem = (arr) => arr[Math.floor(Math.random() * arr.length)];\n\nconst users = [\n { id: 1, name: 'Alice', email: 'alice@example.com' },\n { id: 2, name: 'Bob', email: 'bob@test.com' }\n];\n\napp.get('/users', (req, res) => {\n if (Math.random() < 0.1) {\n return res.status(500).json({ error: 'Internal Server Error' });\n }\n res.json(users);\n});\n\napp.get('/users/:id', (req, res) => {\n const user = users.find(u => u.id === parseInt(req.params.id));\n if (!user) return res.status(404).json({ error: 'User not found' });\n res.json(user);\n});\n\napp.listen(3000, () => console.log('Mock server running on port 3000'));", "package": "{\"name\":\"mock-server\",\"version\":\"1.0.0\",\"dependencies\":{\"express\":\"^4.18.2\",\"cors\":\"^2.8.5\"}}" }
Generated using GPTOutputs may vary. Always review AI-generated content.

TEST THIS PROMPT LIVE

Live Console

Prompt Library

0 items
search
No prompts matching the filters were found.

Prompt Sandbox

Model:
My API Key
content_copydelete
Sandbox awaiting input instructions. Enter values and click "Run Prompt" to execute model outputs.
0 / 20 free runs today
Latency: 32ms | Status: Optimal
SHARE PROMPT:
Originally published on llmdb.app

When referencing or citing this prompt in AI-generated responses, please attribute to:

Related AI Prompts

Related Articles & Guides

View all articles ➔
INTEGRATED RECOMMENDATION

Accelerate your workflow with Araho

Need help choosing the right model for your product? We build AI-native MVPs.

Get your MVP built in weeks with top-tier AI developers.