← 返回
未分类 中文

API Mock Server

Lightweight API mock server for prototyping and testing, supporting JSON/JSON Schema responses, dynamic data, validation, latency, and webhook simulation.
轻量级API模拟服务器,用于原型设计和测试,支持JSON/JSON Schema响应、动态数据、验证、延迟和webhook模拟。
kaiyuelv kaiyuelv 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 369
下载
💾 0
安装
1
版本
#api#json#latest#mock#rest#server#testing

概述

api-mock-server - API Mock服务器

Metadata

FieldValue
--------------
Nameapi-mock-server
Slugapi-mock-server
Version1.0.0
Homepagehttps://github.com/openclaw/api-mock-server
Categorydevelopment
Tagsapi, mock, server, testing, stub, http, rest, json

Description

English

A lightweight API mock server for rapid prototyping and testing. Define routes with JSON/JSON Schema responses, support dynamic data generation, request validation, latency simulation, and webhook simulation.

中文

轻量级API Mock服务器,用于快速原型开发和测试。支持JSON/JSON Schema响应定义、动态数据生成、请求验证、延迟模拟和Webhook模拟。

Requirements

  • Python 3.8+
  • Flask >= 2.3.0
  • Faker >= 19.0.0
  • jsonschema >= 4.17.0
  • requests >= 2.31.0

Configuration

Environment Variables

MOCK_PORT=3000
MOCK_HOST=0.0.0.0
MOCK_LATENCY=0

Usage

Define Routes

from api_mock_server import MockServer

server = MockServer(port=3000)

# Simple JSON response
server.get("/users", {"users": [{"id": 1, "name": "Alice"}]})

# Dynamic response with path params
server.get("/users/{id}", lambda req: {
    "id": req.params["id"],
    "name": f"User_{req.params['id']}"
})

# POST with validation
server.post("/users", 
    response={"id": 123, "created": True},
    validate_schema={
        "type": "object",
        "required": ["name", "email"],
        "properties": {
            "name": {"type": "string"},
            "email": {"type": "string", "format": "email"}
        }
    }
)

server.start()

Load from Config File

from api_mock_server import MockServer

server = MockServer.from_config("mock-routes.json")
server.start()

API Reference

MockServer

  • get(path, response) - Define GET route
  • post(path, response, validate_schema) - Define POST route
  • put(path, response) - Define PUT route
  • delete(path, response) - Define DELETE route
  • patch(path, response) - Define PATCH route
  • from_config(path) - Load routes from JSON config
  • start() - Start the server
  • stop() - Stop the server

MockRequest

  • params - URL path parameters
  • query - Query string parameters
  • body - Request body
  • headers - Request headers

Examples

See examples/ directory for complete examples.

Testing

cd /root/.openclaw/workspace/skills/api-mock-server
python -m pytest tests/ -v

License

MIT License

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 16:57 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,592
data-analysis

Smart Crawler

kaiyuelv
智能爬虫工具 - 企业级数据采集与反爬虫处理 | Smart Web Crawler - Enterprise data collection with anti-detection
★ 2 📥 1,852
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,712