Mock APIs#

What is a mock API?#

Create fully functional API endpoints without server-side code. Define endpoints, set response bodies with dynamic data, and share a working API URL with your team.

Mock endpoints are served at:

https://mocklane.com/m/{workspace-short-id}{path}

# Example:
GET https://mocklane.com/m/abc-xyz/api/users
GET https://mocklane.com/m/abc-xyz/api/users/42

How do I create a mock API endpoint?#

  1. 1Navigate to your workspace → Mocks tab.
  2. 2Click New Mock.
  3. 3Set the HTTP method (GET, POST, PUT, PATCH, DELETE).
  4. 4Set the path (e.g., /api/users or /api/users/:id).
  5. 5Click Create to open the editor.
New Mock Endpoint dialog with a name, the GET method and the path /api/orders
A mock needs a method and a path. Everything else has a sensible default.
Use path parameters with a colon prefix: /api/users/:id matches requests like /api/users/123.

Response Body & Status#

Configure the response consumers will receive:

  • Status Code — 200, 201, 404, 500, etc.
  • Response Headers — Custom headers (Content-Type defaults to application/json).
  • Response Body — JSON with optional template variables.
  • Response Delay — Simulate latency in milliseconds.

How do I generate dynamic response data?#

Embed dynamic generators in your JSON response using {{...}} syntax. Each call produces fresh random values.

Mock editor with a JSON response body using template variables, beside the template helper list
Template the response body and each call fills the values in afresh.
json·Response body with generators
{
  "id": "{{randomUUID}}",
  "name": "{{faker.fullName}}",
  "email": "{{faker.email}}",
  "age": "{{randomInt 18 65}}",
  "avatar": "{{faker.avatar}}",
  "joined": "{{now}}",
  "address": {
"city": "{{faker.city}}",
"country": "{{faker.country}}"
  }
}

Each request returns unique data:

json·Example response
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Emma Johnson",
  "email": "emma.johnson@example.com",
  "age": 34,
  "avatar": "https://i.pravatar.cc/150?u=550e8400",
  "joined": "2026-04-12T10:30:00Z",
  "address": {
"city": "San Francisco",
"country": "United States"
  }
}
The Try It panel showing a generated JSON response with a name, email, company and city
Try It calls the mock exactly as your app would.

Generator Reference#

MockLane includes 121 built-in generators, plus direct access to any Faker method via {{faker.method()}}. Use the Template Helper picker in the editor or type them manually.

Identity

TemplateExample
{{faker.firstName}}Emma
{{faker.lastName}}Johnson
{{faker.fullName}}Emma Johnson
{{faker.email}}emma@example.com
{{faker.username}}emma_j92
{{faker.phone}}+1-555-0142
{{faker.avatar}}https://i.pravatar.cc/150?u=...

Location

TemplateExample
{{faker.city}}San Francisco
{{faker.country}}United States
{{faker.address}}123 Main St
{{faker.zipCode}}94102
{{faker.latitude}}37.7749
{{faker.longitude}}-122.4194

Internet

TemplateExample
{{faker.url}}https://example.com/page
{{faker.domain}}example.com
{{faker.ipv4}}192.168.1.42
{{faker.ipv6}}2001:0db8:85a3:...
{{faker.userAgent}}Mozilla/5.0 ...
{{faker.slug}}my-awesome-post

Numbers & IDs

TemplateExample
{{randomUUID}}550e8400-e29b-41d4-...
{{randomInt 1 1000}}42
{{randomFloat 0 100 2}}73.25
{{autoIncrement}}1, 2, 3, ...

Date & Time

TemplateExample
{{now}}2026-04-12T10:30:00Z
{{faker.pastDate}}2025-08-14
{{faker.futureDate}}2027-01-20
{{faker.timestamp}}1744468200

Commerce

TemplateExample
{{faker.price}}29.99
{{faker.productName}}Wireless Headphones
{{faker.companyName}}Acme Corp
{{faker.currencyCode}}USD

Text

TemplateExample
{{faker.word}}synergy
{{faker.sentence}}The quick brown fox...
{{faker.paragraph}}Lorem ipsum dolor sit...
{{faker.title}}Senior Developer

Color & Media

TemplateExample
{{faker.hexColor}}#3B82F6
{{faker.rgbColor}}rgb(59, 130, 246)
{{faker.imageUrl}}https://picsum.photos/...
{{faker.mimeType}}application/json

How do I return different responses for different requests?#

Return different responses based on the incoming request. Each rule has its own status code, headers, and body.

Match conditions can test against:

  • Headers — e.g., when Authorization contains "Bearer".
  • Query Parameters — e.g., when status=active.
  • Body Fields — e.g., when type equals "premium".
  • Path Parameters — e.g., when :id equals "404".

Rules are evaluated in priority order. First match wins. If none match, the default response is returned.

How do I change the response on each call?#

Define a series of responses returned in order, one per request. Useful for simulating state changes:

Sequence example
Step 1 → 200 {"status": "pending"}
Step 2 → 200 {"status": "processing"}
Step 3 → 200 {"status": "completed"}
     ↩ loops back to Step 1

When Loop is enabled, the sequence restarts after the last step. Otherwise, the last step repeats indefinitely.

How do I serve a JSON file as an API?#

Put a JSON array on the endpoint's Static Data tab and it serves that array, filtered by exact-match query parameters such as ?role=admin:

MethodPathDescription
GET/api/usersReturns the array
GET/api/users/:idThe item with that id (a second mock whose path ends in /:id)

Immutable Mode#

Enable Immutable Mode to restrict an endpoint to GET requests only. All write methods return 405 Method Not Allowed. Useful for exposing read-only data.

How do I simulate API errors and failures?#

Test error handling by configuring:

  • Error Rate — Percentage of requests that return an error (0–100%).
  • Error Status — HTTP status code for errors (e.g., 500, 503).
  • Error Body — Custom JSON body for error responses.

Example: set 20% error rate with 503 status to simulate intermittent outages.

Mock URL#

Every mock endpoint has a live URL displayed at the top of the editor. Use it in your frontend, mobile app, or any HTTP client:

bash·Usage examples
# cURL
curl https://mocklane.com/m/abc-xyz/api/users

# JavaScript
const res = await fetch("https://mocklane.com/m/abc-xyz/api/users");
const data = await res.json();

# Python
import requests
r = requests.get("https://mocklane.com/m/abc-xyz/api/users")
data = r.json()

MockLane © 2026 · Built for developers

Go to Dashboard