API Reference for Mockarty
Table of Contents
- API Overview
- Swagger Documentation
- Mock Management
- Proxy Mode
- Store Management
- Faker and JsonPath
- Usage Examples
API Overview
New to Mockarty? Start with the Quick Start guide.
Base URL
HTTP: http://localhost:5770
Content Type
Content-Type: application/json
Accept: application/json
HTTP Status Codes
200- OK (successful request)201- Created (resource created)204- No Content (successful deletion)400- Bad Request (invalid request)404- Not Found (resource not found)500- Internal Server Error
Swagger Documentation
Accessing Swagger UI
After starting Mockarty, the Swagger UI is available at:
http://localhost:5770/swagger/
Swagger JSON
The specification in JSON format:
http://localhost:5770/swagger/doc.json
Swagger YAML
The specification in YAML format:
http://localhost:5770/swagger/swagger.yaml
Mock Management
Create/Update a Mock
POST /mock/create
Creates a new mock or updates an existing one (by ID).
Request Body:
{
"id": "string", // Unique mock ID
"namespace": "string", // Namespace (optional, default: "default")
"chainId": "string", // Chain ID (optional)
"priority": 0, // Priority (optional, default: 0)
"ttl": 3600000, // TTL in milliseconds (optional, 0 = unlimited)
"useLimiter": 100, // Usage limit (optional, 0 = unlimited)
"http": { // HTTP configuration (for HTTP mocks)
"route": "/api/users/:id",
"httpMethod": "GET",
"conditions": [...], // Request body conditions (see JsonPath Guide)
"queryParams": [...], // Query parameter conditions
"header": [...] // Header conditions
},
"grpc": { // gRPC configuration (for gRPC mocks)
"grpcServiceName": "UserService",
"grpcMethod": "GetUser",
"conditions": [...], // Request body conditions
"meta": [...] // Metadata conditions
},
"mcp": { // MCP configuration (for MCP mocks)
"serverName": "example-server",
"tool": "tool_name", // Tool name, method is automatically "tools/call"
"conditions": [...]
},
"response": { // Simple response
"statusCode": 200,
"headers": {...}, // Headers for HTTP or meta for gRPC/MCP
"payload": {...},
"payloadTemplatePath": "string", // Path to template (optional)
"delay": 1000 // Delay in milliseconds (optional)
// In proxy mode, delay is applied AFTER receiving the response
},
"oneOf": { // Multiple responses
"order": "order|random",
"responses": [...]
},
"proxy": { // Proxying
"target": "http://real-service:8080" // Target server URL
},
"extract": { // Data extraction (see [Store Systems](/docs/stores))
"mStore": {...}, // Mock Store
"cStore": {...}, // Chain Store
"gStore": {...} // Global Store
}
}
Response:
{
"overwritten": false,
"mock": {
"id": "string",
"createdAt": 1704096000000,
"useCounter": 0,
"lastUse": null,
...
}
}
Get a Mock
GET /mock/get/{id}
Retrieves a mock by ID.
Response:
{
"id": "string",
"namespace": "string",
"http": {...},
"response": {...},
"useCounter": 5,
"lastUse": 1704096000000,
"createdAt": 1704000000000
}
List Mocks
GET /mock/list
Retrieves a list of mocks with pagination.
Query Parameters:
offset(int, optional) - Pagination offset (default: 0)limit(int, optional) - Maximum number of mocks (default: 50)namespace(string, optional) - Filter by namespace
Response:
{
"mocks": [...],
"total": 100,
"offset": 0,
"limit": 50
}
Delete a Mock
DELETE /mock/delete/{id}
Deletes a mock (marks it as deleted).
Restore a Mock
GET /mock/restore/{id}
Restores a deleted mock.
Mock Logs
GET /mock/logs/{id}
Retrieves the request history for a mock.
Response:
{
"id": "string",
"requests": [
{
"calledAt": "2024-01-01T10:05:00Z",
"req": {
"header": {...},
"body": {...},
"queryParam": {...},
"url": "/stubs/api/users/123"
}
}
]
}
Clear All Mocks
GET /mock/clear
Warning: Deletes ALL mocks permanently!
See also: Web UI Guide for managing mocks through the visual interface.
Proxy Mode
Proxy mode allows you to forward requests to real servers while adding Mockarty’s additional functionality.
Key Features
- Delay - response delay after receiving data from the proxied server
- Header/Meta substitution - replacing headers (HTTP) or meta (gRPC/MCP) from the proxied server response with values from the mock
- Logging - all proxied requests are logged
HTTP Proxy
Delay
Delay is applied after receiving the response from the proxied server:
{
"id": "http-proxy-delay",
"http": {
"route": "/api/users",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users"
},
"response": {
"delay": 1000 // 1 second delay after receiving the response
}
}
Header Substitution
Headers from response.headers overwrite the corresponding headers from the proxied server response:
{
"id": "http-proxy-headers",
"http": {
"route": "/api/users",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users"
},
"response": {
"headers": {
"X-Custom-Header": ["custom-value"],
"Cache-Control": ["no-cache"],
"X-Served-By": ["mockarty"]
}
}
}
Note: Headers support JsonPath and Faker:
{
"response": {
"headers": {
"X-Request-ID": ["$.fake.UUID"],
"X-User-ID": ["$.reqHeader['X-User-ID'][0]"],
"X-Timestamp": ["$.fake.RFC3339"]
}
}
}
gRPC Proxy
Delay
Similar to HTTP, the delay is applied after receiving the response:
{
"id": "grpc-proxy-delay",
"grpc": {
"grpcServiceName": "UserService",
"grpcMethod": "GetUser"
},
"proxy": {
"target": "real-grpc-service:9090"
},
"response": {
"delay": 500
}
}
Meta Substitution
For gRPC, response.headers replace meta headers:
{
"id": "grpc-proxy-meta",
"grpc": {
"grpcServiceName": "UserService",
"grpcMethod": "GetUser"
},
"proxy": {
"target": "real-grpc-service:9090"
},
"response": {
"headers": {
"x-custom-meta": ["custom-value"],
"x-trace-id": ["$.fake.UUID"],
"x-user-id": ["$.req.id"]
}
}
}
MCP Proxy
Delay and Meta
MCP works similarly to gRPC:
{
"id": "mcp-proxy",
"mcp": {
"serverName": "example-server",
"tool": "tool_name"
},
"proxy": {
"target": "http://real-mcp:8080/mcp"
},
"response": {
"delay": 300,
"headers": {
"x-custom-meta": ["custom-value"]
}
}
}
Combining Features
All features can be combined:
{
"id": "proxy-full",
"http": {
"route": "/api/users/:id",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users/:id"
},
"response": {
"delay": 2000,
"headers": {
"X-Response-Time": ["2000ms"],
"X-Served-By": ["mockarty"],
"X-Request-ID": ["$.fake.UUID"],
"X-Original-User": ["$.reqHeader['X-User-ID'][0]"]
}
}
}
Use Cases for Testing
Proxy mode with delay and header/meta substitution enables:
- Timeout testing - add delay to verify handling of slow responses
- Error simulation - substitute headers to simulate various server states
- Toxicity injection - introduce delays and modify metadata to test client resilience
- Logging - all proxied requests are saved in mock logs
Store Management
For a comprehensive guide on store concepts and patterns, see the Store Systems documentation.
Global Store
Get Global Store
GET /mock/store/global
Query Parameters:
namespace(string, optional) - Namespace (default: “default”)
Response:
{
"key1": "value1",
"key2": {
"nested": "data"
}
}
Add Data to Global Store
POST /mock/store/global
Query Parameters:
namespace(string, optional) - Namespace (default: “default”)
Request Body:
{
"key": "totalUsers",
"value": 100
}
Delete Data from Global Store
DELETE /mock/store/global/{key}
Query Parameters:
namespace(string, optional) - Namespace (default: “default”)
Chain Store
Get Chain Store
GET /mock/store/chain/{chainId}
Query Parameters:
namespace(string, optional) - Namespace (default: “default”)
Add Data to Chain Store
POST /mock/store/chain/{chainId}
Query Parameters:
namespace(string, optional) - Namespace (default: “default”)
Request Body:
{
"key": "orderId",
"value": "order-123"
}
Delete Data from Chain Store
DELETE /mock/store/chain/{chainId}/{key}
Query Parameters:
namespace(string, optional) - Namespace (default: “default”)
Faker and JsonPath
This section provides a quick overview. For full details, see the Faker Functions Reference and the JsonPath Guide.
Using Faker in Responses
Faker functions are available via the $.fake. prefix:
{
"response": {
"payload": {
"id": "$.fake.UUID",
"name": "$.fake.FirstName",
"email": "$.fake.Email",
"phone": "$.fake.Phone",
"address": "$.fake.Address",
"createdAt": "$.fake.RFC3339",
"price": "$.fake.Price",
"isActive": "$.fake.Bool"
}
}
}
Using JsonPath for Data Extraction
From the Request Body
{
"response": {
"payload": {
"userId": "$.req.userId",
"userName": "$.req.user.name",
"items": "$.req.items[*].id"
}
}
}
From Headers
{
"extract": {
"mStore": {
"authToken": "$.reqHeader.Authorization[0]",
"userId": "$.reqHeader['X-User-ID'][0]"
}
}
}
From Store
See Store Systems for details on Global, Chain, and Mock stores.
{
"response": {
"payload": {
"totalUsers": "$.gS.totalUsers",
"orderId": "$.cS.orderId",
"generatedId": "$.mS.generatedId"
}
}
}
Combining Faker and JsonPath
{
"response": {
"payload": {
"id": "$.fake.UUID",
"name": "$.req.name",
"email": "$.fake.Email",
"welcomeMessage": "Hello $.req.name! Your ID is $.fake.UUID"
}
}
}
Extracting Data to Store
Mock Store (mS)
{
"extract": {
"mStore": {
"generatedId": "$.fake.UUIDDigit",
"requestTime": "$.fake.RFC3339",
"clientIP": "$.reqHeader['X-Forwarded-For'][0]"
}
},
"response": {
"payload": {
"id": "$.mS.generatedId",
"processedAt": "$.mS.requestTime"
}
}
}
Chain Store (cS)
{
"chainId": "order-processing",
"extract": {
"cStore": {
"orderId": "$.fake.UUIDDigit",
"customerId": "$.req.customerId",
"totalAmount": "$.sum($.req.items[*].price)"
}
},
"response": {
"payload": {
"orderId": "$.cS.orderId",
"status": "created"
}
}
}
Global Store (gS)
{
"extract": {
"gStore": {
"totalUsers": "$.increment($.gS.totalUsers || 0)",
"lastActiveUser": "$.req.userId",
"systemStats": {
"lastRequest": "$.fake.RFC3339",
"version": "1.0.0"
}
}
},
"response": {
"payload": {
"totalUsersInSystem": "$.gS.totalUsers",
"systemVersion": "$.gS.systemStats.version"
}
}
}
JsonPath Functions
Mathematical Operations
{
"extract": {
"mStore": {
"total": "$.sum($.req.items[*].price)",
"average": "$.divide($.sum($.req.items[*].price), $.length($.req.items))",
"discount": "$.multiply($.req.price, 0.1)"
}
}
}
Working with Arrays
{
"response": {
"payload": {
"itemCount": "$.length($.req.items)",
"firstItem": "$.req.items[0]",
"lastItem": "$.req.items[-1]",
"allIds": "$.req.items[*].id"
}
}
}
Conditional Expressions
{
"extract": {
"mStore": {
"discountPercent": "$.req.isVip ? 0.2 : 0.1",
"finalPrice": "$.multiply($.req.price, $.subtract(1, $.mS.discountPercent))"
}
}
}
Usage Examples
Example 1: Simple HTTP Mock
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "get-user",
"http": {
"route": "/api/users/:id",
"httpMethod": "GET"
},
"response": {
"statusCode": 200,
"payload": {
"id": "$.pathParam.id",
"name": "$.fake.FirstName",
"email": "$.fake.Email"
}
}
}'
Example 2: Mock with Conditions
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "create-user-admin",
"http": {
"route": "/api/users",
"httpMethod": "POST",
"conditions": [
{
"path": "$.role",
"assertAction": "equals",
"value": "admin"
}
]
},
"response": {
"statusCode": 201,
"payload": {
"id": "$.fake.UUID",
"name": "$.req.name",
"email": "$.req.email",
"role": "$.req.role",
"createdAt": "$.fake.RFC3339"
}
}
}'
Example 3: Mock with Chain Store
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "order-create",
"chainId": "order-processing",
"http": {
"route": "/api/orders",
"httpMethod": "POST"
},
"response": {
"statusCode": 201,
"payload": {
"orderId": "$.cS.orderId",
"status": "created"
}
},
"extract": {
"cStore": {
"orderId": "$.fake.UUIDDigit",
"customerId": "$.req.customerId",
"items": "$.req.items"
}
}
}'
Example 4: Mock with Global Store Counter
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "user-register",
"http": {
"route": "/api/users/register",
"httpMethod": "POST"
},
"response": {
"statusCode": 201,
"payload": {
"id": "$.fake.UUID",
"totalUsers": "$.gS.totalUsers"
}
},
"extract": {
"gStore": {
"totalUsers": "$.increment($.gS.totalUsers || 0)"
}
}
}'
Example 5: Mock with Proxying
Basic Proxying
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "proxy-user",
"http": {
"route": "/api/users/:id",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users/:id"
}
}'
Proxying with Delay
Delay is applied after receiving the response from the proxied server:
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "proxy-user-delay",
"http": {
"route": "/api/users/:id",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users/:id"
},
"response": {
"delay": 1000
}
}'
Proxying with Header Substitution (HTTP)
Headers from response.headers replace the corresponding headers in the proxied server response:
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "proxy-user-headers",
"http": {
"route": "/api/users/:id",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users/:id"
},
"response": {
"headers": {
"X-Custom-Header": ["custom-value"],
"X-Another-Header": ["another-value"],
"Cache-Control": ["no-cache"]
}
}
}'
gRPC Proxying with Meta Substitution
For gRPC, headers from response.headers replace meta headers:
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "proxy-grpc-meta",
"grpc": {
"grpcServiceName": "UserService",
"grpcMethod": "GetUser"
},
"proxy": {
"target": "real-grpc-service:9090"
},
"response": {
"headers": {
"x-custom-meta": ["custom-meta-value"],
"x-trace-id": ["trace-123"]
},
"delay": 500
}
}'
MCP Proxying with Meta Substitution
Similar to gRPC, for MCP headers from response.headers replace meta headers:
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "proxy-mcp-meta",
"mcp": {
"serverName": "example-server",
"tool": "tool_name"
},
"proxy": {
"target": "http://real-mcp:8080/mcp"
},
"response": {
"headers": {
"x-custom-meta": ["custom-meta-value"]
},
"delay": 300
}
}'
Combining Delay and Headers
You can combine delay and header substitution:
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "proxy-combined",
"http": {
"route": "/api/users",
"httpMethod": "GET"
},
"proxy": {
"target": "http://real-api:8080/api/users"
},
"response": {
"delay": 2000,
"headers": {
"X-Response-Time": ["2000ms"],
"X-Served-By": ["mockarty-proxy"]
}
}
}'
Example 6: gRPC Mock
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "grpc-get-user",
"grpc": {
"grpcServiceName": "UserService",
"grpcMethod": "GetUser",
"conditions": [
{
"path": "$.id",
"assertAction": "equals",
"value": "123"
}
]
},
"response": {
"statusCode": 0,
"payload": {
"id": "123",
"name": "$.fake.FirstName",
"email": "$.fake.Email"
}
}
}'
Example 7: Mock with OneOf (Multiple Responses)
curl -X POST http://localhost:5770/mock/create \
-H "Content-Type: application/json" \
-d '{
"id": "random-response",
"http": {
"route": "/api/random",
"httpMethod": "GET"
},
"oneOf": {
"order": "random",
"responses": [
{
"statusCode": 200,
"payload": {"result": "success"}
},
{
"statusCode": 200,
"payload": {"result": "partial"}
},
{
"statusCode": 500,
"payload": {"error": "server error"}
}
]
}
}'
Example 8: Working with Global Store via API
# Get Global Store
curl http://localhost:5770/mock/store/global?namespace=default
# Add data
curl -X POST http://localhost:5770/mock/store/global?namespace=default \
-H "Content-Type: application/json" \
-d '{
"key": "systemVersion",
"value": "1.0.0"
}'
# Delete data
curl -X DELETE http://localhost:5770/mock/store/global/systemVersion?namespace=default
Example 9: Working with Chain Store via API
# Get Chain Store
curl http://localhost:5770/mock/store/chain/order-processing?namespace=default
# Add data
curl -X POST http://localhost:5770/mock/store/chain/order-processing?namespace=default \
-H "Content-Type: application/json" \
-d '{
"key": "orderId",
"value": "order-123"
}'
# Delete data
curl -X DELETE http://localhost:5770/mock/store/chain/order-processing/orderId?namespace=default
Faker Functions Reference
See the Faker Functions Reference for the complete list of available Faker functions.
Main Categories:
- Identifiers:
UUID,UUIDDigit,Int,PositiveInt - Personal data:
FirstName,LastName,Name,Email,Phone - Dates and time:
RFC3339,UnixTime,Date,FutureDate,PastDate - Addresses:
Address,City,State,Zip,Country - Business:
Company,JobTitle,Industry - Finance:
Price,CreditCard,Currency - And more…
JsonPath Reference
See the JsonPath Guide for the complete JsonPath guide.
Key Features:
- Data extraction:
$.req.userId,$.reqHeader.Authorization[0] - Array operations:
$.items[*].id,$.items[0],$.items[-1] - Filtering:
$.users[?(@.active == true)] - Recursive search:
$..email - Functions:
$.length(),$.sum(),$.increment(),$.multiply()
Authentication
API Token Authentication
Include the token in the Authorization header:
Authorization: Bearer mk_7_VZeCqexj1wUAIAuiCtEupaAjz4LlSnGVE_0KdGYII=
Or as a query parameter:
GET /mock/list?token=mk_7_VZeCqexj1wUAIAuiCtEupaAjz4LlSnGVE_0KdGYII=
Create tokens via the Web UI (API Tokens page) or Admin API.
Session Authentication
The Web UI uses cookie-based session authentication. Login via POST /api/auth/login with username and password.
Namespace Management
Create Namespace
POST /mock/namespace/create
{
"name": "my-namespace"
}
List Namespaces
GET /ui/api/namespaces
Returns all accessible namespaces for the authenticated user.
Copy Mocks Between Namespaces
POST /mock/namespace/copy
{
"sourceNamespace": "staging",
"targetNamespace": "production",
"mockIds": ["mock-1", "mock-2"]
}
Protocol-Specific Mock Examples
For generating standalone protocol servers, see the Server Generator documentation.
SOAP Mock
{
"id": "soap-get-user",
"soap": {
"soapAction": "GetUser",
"route": "/ws/users"
},
"response": {
"statusCode": 200,
"headers": {"Content-Type": ["text/xml"]},
"payload": "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetUserResponse><User><Id>$.fake.UUID</Id><Name>$.fake.FirstName</Name></User></GetUserResponse></soap:Body></soap:Envelope>"
}
}
GraphQL Mock
{
"id": "graphql-get-user",
"graphql": {
"operationName": "GetUser",
"operationType": "query"
},
"response": {
"statusCode": 200,
"payload": {
"data": {
"user": {
"id": "$.fake.UUID",
"name": "$.fake.FirstName",
"email": "$.fake.Email"
}
}
}
}
}
WebSocket Mock
{
"id": "ws-chat-message",
"socket": {
"socketType": "websocket",
"serverName": "chat-server",
"event": "message"
},
"response": {
"payload": {
"type": "chat",
"message": "$.req.text",
"timestamp": "$.fake.RFC3339"
}
}
}
Kafka Mock
{
"id": "kafka-order-event",
"kafka": {
"topic": "orders",
"serverName": "kafka-server"
},
"response": {
"payload": {
"orderId": "$.fake.UUID",
"status": "processed",
"timestamp": "$.fake.RFC3339"
}
}
}
RabbitMQ Mock
{
"id": "rabbitmq-notification",
"rabbitmq": {
"queue": "notifications",
"serverName": "rabbitmq-server"
},
"response": {
"payload": {
"notificationId": "$.fake.UUID",
"message": "$.req.message",
"sentAt": "$.fake.RFC3339"
}
}
}
SSE Mock
{
"id": "sse-updates",
"sse": {
"route": "/events/updates",
"serverName": "sse-server"
},
"response": {
"payload": {
"event": "update",
"data": {"id": "$.fake.UUID", "value": "$.fake.Int"}
}
}
}
MCP Tool Mock
{
"id": "mcp-search-tool",
"mcp": {
"serverName": "ai-server",
"tool": "search_documents",
"conditions": [
{
"path": "$.query",
"assertAction": "notEmpty"
}
]
},
"response": {
"payload": {
"results": [
{"title": "$.fake.Sentence", "url": "$.fake.URL", "score": "$.fake.Price"}
]
}
}
}
Batch Operations (UI API)
Batch Delete Mocks
POST /ui/api/mocks/batch-delete
{
"ids": ["mock-1", "mock-2", "mock-3"]
}
Batch Restore Mocks
POST /ui/api/mocks/batch-restore
{
"ids": ["mock-1", "mock-2"]
}
Batch Tag Mocks
POST /ui/api/mocks/batch-tags
{
"ids": ["mock-1", "mock-2"],
"addTags": ["production", "v2"],
"removeTags": ["deprecated"]
}
Health and Monitoring Endpoints
| Endpoint | Description |
|---|---|
| GET /health | Comprehensive health check with component status |
| GET /health/live | Liveness probe (returns 200 if running) |
| GET /health/ready | Readiness probe (returns 200 if ready to serve) |
| GET /metrics | Prometheus-compatible metrics |
| GET /swagger/ | Swagger UI for interactive API exploration |
| GET /swagger/doc.json | Swagger specification (JSON) |
Health Response Example
{
"status": "up",
"releaseId": "1.2.3",
"checks": {
"database": {"status": "up"},
"cache": {"status": "up"}
}
}
MCP Server Endpoint
Mockarty exposes an MCP (Model Context Protocol) server for AI tool integration.
SSE Endpoint: GET /mcp/sse
Connect external AI tools (Claude Desktop, Cursor, etc.) to create and manage mocks via natural language. See the Integrations Guide for setup instructions.
Authentication: Include API token in request headers:
Authorization: Bearer mk_YOUR_TOKEN_HERE
Rate Limiting and Limits
- API requests are rate-limited based on your license tier
- Default limits: configurable per namespace
- Token-based rate limiting per API key
- gRPC: only unary methods supported for proxy mode (no stream client proxy)
Related Documentation
- Quick Start - Get up and running quickly
- Faker Functions Reference - Complete list of dynamic data generators
- JsonPath Guide - Data extraction and transformation
- Store Systems - Global, Chain, and Mock store patterns
- Web UI Guide - Visual interface for managing mocks
- Server Generator - Generate standalone MCP/gRPC servers
- Integrations Guide - Connect with external tools and CI/CD
- Docker & Deployment - Production deployment guide