A single binary that reads your OpenAPI/GraphQL schema and instantly serves a realistic mock API β no internet required.
Most dev environments assume stable internet. In India and many other countries, that assumption breaks constantly β during travel, power outages, or in areas with poor connectivity.
Frontend and mobile developers constantly need to test against backend APIs that aren't available offline. Existing tools fall short:
| Tool | Problem |
|---|---|
| WireMock | Heavyweight, Java-based, needs JVM |
| MSW | Browser-only, not CLI-native |
| Postman Mock | Requires cloud + login |
| json-server | No schema support, no GraphQL |
mockr fills the gap: a single binary, zero dependencies, starts in under a second, works 100% offline.
- β
OpenAPI 3.x support β reads your
openapi.yamloropenapi.json - β
GraphQL support β reads
.graphqlschema files - β Hand-written YAML β define mocks without a full schema
- β Auto-generated responses β realistic fake data from schema types
- β Configurable latency β simulate slow networks
- β Error injection β randomly return 4xx/5xx to test resilience
- β Request logging β see every request hit in the terminal
- β CORS enabled by default β works with any frontend
- β Hot reload β edit schema, server updates instantly
- β Single binary β no Node, no Java, no Docker
go install github.com/yourusername/mockr@latest# Linux
curl -L https://github.com/yourusername/mockr/releases/latest/download/mockr-linux-amd64 -o mockr
chmod +x mockr
sudo mv mockr /usr/local/bin/
# macOS
brew install yourusername/tap/mockrmockr serve --schema openapi.yamlmockr serve --schema schema.graphql --port 4000mockr serve --schema mocks.yamlYour mock server is now live at http://localhost:8080.
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths:
/users:
get:
summary: Get all users
responses:
'200':
description: A list of users
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
email:
type: string
format: emailroutes:
- method: GET
path: /users
status: 200
response:
- id: 1
name: Ravi Kumar
email: ravi@example.com
- method: POST
path: /login
status: 200
response:
token: "mock-jwt-token-xyz"
- method: GET
path: /orders/:id
status: 200
response:
orderId: "{{params.id}}"
status: deliveredtype Query {
user(id: ID!): User
users: [User]
}
type User {
id: ID!
name: String!
email: String!
createdAt: String!
}mockr [command] [flags]
Commands:
serve Start the mock server
validate Validate a schema file without serving
generate Generate a sample mock YAML from a schema
Flags for serve:
--schema Path to schema file (required)
--port Port to listen on (default: 8080)
--latency Add artificial latency in ms (e.g. --latency 300)
--error-rate Percentage of requests to fail (e.g. --error-rate 10)
--watch Enable hot reload on schema change
--log Log all incoming requests (default: true)
--cors Enable CORS headers (default: true)
# Serve with 300ms simulated latency
mockr serve --schema api.yaml --latency 300
# Randomly fail 20% of requests (resilience testing)
mockr serve --schema api.yaml --error-rate 20
# Watch for schema changes (hot reload)
mockr serve --schema api.yaml --watch
# Run on a custom port
mockr serve --schema api.yaml --port 3001
# Validate schema without starting server
mockr validate --schema api.yamlWhen no explicit response is defined, mockr auto-generates realistic data from the schema:
| Schema Type | Generated Value |
|---|---|
string |
Random word |
string (email) |
user@example.com |
string (uuid) |
Valid UUID v4 |
string (date) |
2024-03-15 |
integer |
Random int |
boolean |
true or false |
array |
2β5 generated items |
mockr/
βββ cmd/
β βββ mockr/
β βββ main.go # CLI entry point
βββ internal/
β βββ server/ # HTTP/GraphQL server
β βββ parser/ # OpenAPI + GraphQL + YAML parsers
β βββ generator/ # Fake data generator
β βββ middleware/ # Latency, error injection, logging
β βββ config/ # CLI flags and config
βββ examples/
β βββ openapi.yaml
β βββ schema.graphql
β βββ mocks.yaml
βββ go.mod
βββ go.sum
βββ README.md
- π§βπ» Hackathons β frontend and backend teams work in parallel without waiting on each other
βοΈ Travel β develop and test without airport/train WiFi- π Backend outages β frontend dev continues uninterrupted
- π± Mobile dev in low-connectivity areas β test app behaviour on slow/no networks
- π§ͺ CI pipelines β spin up a mock server without real backend dependencies
- WebSocket mock support
- Response templating with Faker.js-style variables
- UI dashboard to inspect requests
- gRPC schema support
- Export recorded real traffic as mock schema
git clone https://github.com/yourusername/mockr.git
cd mockr
go mod tidy
go run ./cmd/mockr serve --schema examples/openapi.yaml