Tutorial

How to Create a Mock API (REST)

This guide explains every field of the REST generator and walks you step by step: selecting the endpoint path, methods, headers, dynamic variables, optional Bearer protection, and response body.

1) Open the REST generator

Sign in, then open Generate REST Mock. You’ll see a form with fields for path, methods, headers, and response JSON.

2) Choose an endpoint path

Enter the path your mock should respond to, for example /api/users or /v1/orders. Avoid spaces and keep it URL‑friendly. This becomes part of the final URL you’ll call.

Tip: Group paths with prefixes like /demo/ or /sandbox/ to keep your routes organized.

3) Select allowed methods

Pick one or more HTTP methods (e.g., GET, POST, PUT, DELETE). Calls using other methods will be rejected. If you plan to test form submissions, include POST; for reads, include GET.

4) Optional: required headers

Add header names that clients must send, such as X-Client or X-Env. If a required header is missing, the mock returns a clear error response.

Tip: Use headers to emulate multi‑tenant routing or environment flags during frontend testing.

5) Optional: protect with Bearer token

Enable “Protected by Bearer token” to require clients to send Authorization: Bearer <token>. On premium plans, you can view and regenerate the token from your dashboard.

curl -H "Authorization: Bearer YOUR_TOKEN" https://mockhub.ovh/your-path

6) Write the response body

Paste or craft a valid JSON object. Keep the structure close to your intended real API. If preferred, use AI to draft a first version, then edit fields and types.

{ "users": [ { "id": 1, "name": "Alice" }, { "id": 2, "name": "Bob" } ], "count": 2 }

7) Use dynamic variables (optional)

You can embed dynamic placeholders in your JSON that resolve at request time, e.g. {{uuid}}, {{email}}, {{timestamp}}. The engine replaces them with fresh values on each call.

{ "requestId": "{{uuid}}", "user": { "email": "{{email}}" }, "receivedAt": "{{timestamp}}" }
Tip: Combine static fields with dynamic variables to simulate realistic payloads during UI flows.

8) Create the endpoint

Submit the form. You’ll get the endpoint URL and, if secured, the Bearer token or password data. Save these details for your tests.

9) Test the mock

Call the URL from your app or CLI. Include required headers and Bearer auth if enabled.

fetch('https://mockhub.ovh/your-path', {
  method: 'GET',
  headers: {
    'X-Client': 'demo',
    'Authorization': 'Bearer YOUR_TOKEN'
  }
}).then(r => r.json()).then(console.log);

10) Next: scenarios (optional)

Add scenarios to simulate alternate responses, status codes, delays and error rates, then switch the active scenario to test failure modes.

Continue with: How to Add a Scenario and How to Switch Scenario.