Generate a Mock API from JSON
Learn how to turn any JSON payload into a live, shareable REST endpoint for prototyping and testing.
Last updated:
Frontend developers often need to prototype against an API that doesn't exist yet. DataLensia's Mock API Generator lets you create a live endpoint in seconds โ no server, no deployment, no sign-up.
๐ฉ The Scenario
You're building a dashboard and the backend team hasn't shipped the /api/users endpoint yet. You have a sample response:
[
{"id": 1, "name": "Alice", "role": "admin", "lastLogin": "2025-01-15"},
{"id": 2, "name": "Bob", "role": "editor", "lastLogin": "2025-01-14"}
]
๐ ๏ธ Step-by-Step
- Open the Mock API Tool.
- Paste your JSON into the editor or upload a file.
- Configure the endpoint:
- Status Code:
200 OK(or any other code for testing error handling). - HTTP Method:
GET(restrict to specific methods if needed). - Delay: Add
500msof artificial latency to simulate real network conditions. - Content-Type: Defaults to
application/json.
- Status Code:
- Click Generate Link.
- Copy the generated URL and use it in your frontend code:
const response = await fetch("https://datalensia.com/api/mock/m1.eJy...");
const users = await response.json();
๐ฒ Dynamic Values with Faker.js
Make your mock responses dynamic! Use placeholders that generate new data on every request:
{
"id": "{{faker.string.uuid()}}",
"name": "{{faker.person.fullName()}}",
"email": "{{faker.internet.email()}}",
"createdAt": "{{faker.date.recent()}}"
}
Every time the endpoint is called, fresh data is generated using Faker.js.
๐ Path-Based Sub-Resources
The Mock API supports nested paths. If you generate a mock at https://datalensia.com/api/mock/<data>, you can also access:
https://datalensia.com/api/mock/<data>/usersโ returns theuserskey from your JSON.https://datalensia.com/api/mock/<data>/users/0โ returns the first user.
๐งช Simulation Panel
The Mock API tool includes a built-in Simulation tab where you can:
- Send test requests to your endpoint.
- See the exact response headers, body, and timing.
- Verify that your status codes and delays work as expected.
๐ Auto-Generated Documentation
The Docs tab automatically generates API documentation for your mock endpoint, including:
- Endpoint URL.
- Expected response format.
- TypeScript type definitions for the response.
๐ Try it now
Create your first mock endpoint in the Mock API Generator.