Imagine this: Your frontend team is ready to build a new feature, but the backend API isn't ready yet.
The UI designs are approved. The developers are ready to write code. The test scenarios are prepared.
But there's one problem.
The frontend team is waiting for the backend team to finish the API.
A few days pass. Then a few more.
Meanwhile, development slows down, testing gets delayed, and the release deadline starts getting closer.
Sound familiar?
This is one of the most common challenges in modern software development.
But what if frontend and backend teams could work independently without waiting for the actual API implementation?
That's where API Mocking comes in!
API mocking allows developers and testers to work with simulated API responses before the real backend service is available.
In this article, we'll explore how API mocking works, why it matters, how to create mock APIs, and how teams can use it to accelerate parallel development.
Explore the complete guide: What Is API Mocking? How and When to Mock APIs – TotalShiftLeft
- What Is API Mocking?
API mocking is the process of replacing a real API with a simulated API that returns predefined or dynamically generated responses.
Instead of waiting for the actual backend implementation, developers can send requests to a mock API and receive realistic responses.
Let's understand with an example.
Imagine you're building an e-commerce application.
Your frontend team needs an Orders API, but the backend team hasn't implemented it yet.
The expected API might look like this:
API Endpoint:
GET /api/v1/orders/101 Expected Response:
{ "id": "101", "customerName": "John", "total": 250, "status": "PENDING" } The frontend developer can use a mock server to return this response immediately.
Now the frontend team can:
- Build the order details page.
- Display customer information.
- Implement loading states.
- Handle API errors.
- Test different UI scenarios.
All without waiting for the backend implementation!
That's the real power of API mocking: development continues even when dependencies aren't ready.
- Why Is API Mocking Important for Parallel Development?
In modern applications, multiple teams often work on different components simultaneously.
For example:
- Frontend team builds the user interface.
- Backend team develops API endpoints.
- QA team prepares test scenarios.
- Integration team connects external services.
Without API mocking, these teams may become dependent on one another.
API mocking helps remove that dependency.
Here are five major benefits.
- Frontend and Backend Development Can Happen Simultaneously
Frontend developers can start building screens using mock responses while backend developers implement the actual API.
- Faster Testing
QA engineers don't need to wait for every backend endpoint to become available before testing application behavior.
- Better Error Scenario Testing
Real APIs may not consistently produce errors such as 400, 401, 500, or 503.
Mock servers allow testers to simulate these responses whenever required.
- Reduced Dependency on Third-Party Services
If an external payment or shipping API is slow, unavailable, or rate-limited, a mock can help teams continue development and testing.
- Faster CI/CD Execution
Mocked dependencies help create predictable and repeatable automated tests without relying on multiple external services.
- Real-World Example: Building an E-Commerce Application Using API Mocking
Let's imagine three teams working on an e-commerce application.
Frontend Team
Needs APIs to display:
- Product details.
- Customer information.
- Order history.
- Payment status.
Backend Team
Is currently implementing:
- Product API.
- Orders API.
- Payment API.
QA Team
Needs to test:
- Successful order creation.
- Invalid payment details.
- Empty order responses.
- Failed payment scenarios.
Without mocking, all three teams may have to wait for backend development.
With API mocking, everyone can begin working using an agreed API contract.
For example:
| Scenario | Mock API Response |
|---|---|
| Successful order | 201 Created |
| Invalid request | 400 Bad Request |
| Unauthorized access | 401 Unauthorized |
| Order not found | 404 Not Found |
| Payment service unavailable | 503 Service Unavailable |
The frontend team can test different UI states, QA can validate error handling, and backend developers can implement the actual service.
Everyone progresses simultaneously.
- How to Create a Mock API Using Different Tools
Several tools make API mocking easier.
Let's explore four popular approaches.
A. Prism – Generate Mock APIs From OpenAPI Specifications
If your team already has an OpenAPI specification, Prism can generate a mock server directly from it.
First, create an OpenAPI file.
openapi.yaml
openapi: 3.0.0 info: title: Orders API version: 1.0.0 paths: /orders/{id}: get: summary: Get order details parameters: - name: id in: path required: true schema: type: string responses: '200': description: Successful response content: application/json: schema: type: object properties: id: type: string sku: type: string qty: type: integer status: type: string Install and start Prism:
npm install -g @stoplight/prism-cli prism mock openapi.yaml --port 4010 Now send a request:
curl http://localhost:4010/orders/101 Prism can generate schema-based responses without requiring the real backend implementation.
This is especially useful when teams agree on the API specification early.
B. WireMock – Simulate Specific API Responses
WireMock is useful when you want complete control over API responses.
For example, imagine you want to simulate a payment service failure.
Create a mapping:
{ "request": { "method": "POST", "urlPath": "/payments" }, "response": { "status": 503, "headers": { "Content-Type": "application/json", "Retry-After": "5" }, "jsonBody": { "error": "payment_service_unavailable" } } } Now your application can receive a simulated 503 Service Unavailable response.
QA engineers can verify whether the application:
- Displays an appropriate error message.
- Handles retries correctly.
- Avoids duplicate payments.
- Recovers when the service becomes available.
C. Postman Mock Servers
Postman allows developers to create mock servers from saved request collections and example responses.
A typical workflow:
- Create a collection.
- Add API requests.
- Save example responses.
- Create a mock server.
- Share the mock URL with frontend and QA teams.
This is a convenient option for API design discussions and collaborative development.
D. Playwright API Mocking
Frontend developers can also mock API responses directly inside browser tests using Playwright.
Example:
await page.route('**/api/orders/101', async route => { await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: '101', status: 'PENDING', total: 250 }) }); }); This intercepts the browser request and returns the simulated response.
It's particularly useful for testing frontend behavior without depending on a running backend.
- Static vs Dynamic vs Stateful API Mocking
Not every mock API behaves the same way.
Understanding these approaches helps you choose the right mocking strategy.
Static Mocking
A static mock always returns the same predefined response.
Example:
{ "status": "SUCCESS" } Best for: Simple UI development and basic test scenarios.
Dynamic Mocking
A dynamic mock changes its response based on request parameters, headers, or body content.
For example:
- Valid customer ID →
200 OK - Invalid customer ID →
404 Not Found - Missing authentication →
401 Unauthorized
Best for: Functional testing and different business scenarios.
Stateful Mocking
A stateful mock remembers previous requests.
For example:
- Send POST request to create an order.
- Receive the generated order ID.
- Send GET request using that ID.
- Retrieve the previously created order.
Best for: Multi-step workflows and integration scenarios.
For complex development and testing workflows, dynamic and stateful mocks can be more useful than simple static responses.
- API Mocking Is Powerful, But Don't Forget API Contract Testing
Here's an important situation.
Imagine your frontend team builds an application using a mock API.
The mock returns:
{ "customerName": "John" } But when the real backend is released, it returns:
{ "fullName": "John" } Your frontend might break even though it passed every mock-based test.
Why?
Because the mock and the actual API are no longer aligned.
This problem is called mock drift.
To avoid it, teams should follow these practices:
- Agree on the API contract first.
Define request structures, response formats, data types, and error codes before development begins.
- Generate mocks from the API specification.
Whenever possible, use OpenAPI to generate mocks instead of manually maintaining separate response definitions.
- Version your API specifications.
Track specification changes in version control so both teams work with the same contract.
- Perform contract testing.
Verify that the actual API implementation follows the agreed specification.
- Test against the real API regularly.
Mock-based tests cannot prove that two real services integrate correctly.
Remember:
API mocking helps teams work independently. Contract testing ensures they stay connected.
- How to Integrate Mock APIs Into CI/CD Pipelines
API mocking becomes even more valuable when it is part of an automated development workflow.
Consider a GitHub Actions pipeline.
You can run a mock API server as a service during automated testing.
Example:
name: API Consumer Tests on: push: branches: - main jobs: test: runs-on: ubuntu-latest services: mock: image: stoplight/prism:4 ports: - 4010:4010 steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Install Dependencies run: npm ci - name: Run API Tests run: npm test env: ORDERS_API_URL: http://localhost:4010 This example demonstrates how a mock server can be made available to automated tests.
For production pipelines, also add:
- A health check to ensure the mock server is ready.
- Contract validation against the real provider.
- Separate integration tests.
- Version-controlled API specifications.
The advantage is that consumer tests can run without waiting for every dependent service to be deployed.
- Common API Mocking Mistakes to Avoid
API mocking is useful, but incorrect implementation can create false confidence.
Here are six mistakes worth avoiding.
- Mocking Only Successful Responses
Your application must also handle errors, timeouts, empty responses, and invalid inputs.
- Creating Mocks Without an API Contract
Different teams may implement different assumptions about the same endpoint.
- Never Updating Mock Responses
When the actual API changes, outdated mocks can mislead developers.
- Treating Mock Tests as Real Integration Tests
A successful mock-based test doesn't prove that the real backend works correctly.
- Ignoring Authentication and Authorization
Mocking should include realistic security scenarios where appropriate.
- Forgetting to Test Against the Real API
Mocks should accelerate development, not permanently replace integration testing.
- How AI Can Make API Mocking More Efficient
As applications grow, manually creating and maintaining mock responses can become time-consuming.
AI-powered API testing can help teams:
- Generate API test scenarios from specifications.
- Identify missing test cases.
- Create positive and negative test scenarios.
- Improve API test coverage.
- Support automated API testing workflows.
- Detect potential contract inconsistencies.
At TotalShiftLeft, we're focused on helping developers and QA teams improve API quality through AI-powered test generation, automated execution, and shift-left testing practices.
The objective is simple: find issues earlier, reduce repetitive work, and make API testing part of everyday development.
- A Practical API Mocking Workflow for Development Teams
If your team wants to start using API mocking, here's a simple workflow to follow.
| Step | Activity |
|---|---|
| 1 | Define the API requirements |
| 2 | Create and review the OpenAPI specification |
| 3 | Generate or configure the mock server |
| 4 | Share the mock endpoint with frontend and QA |
| 5 | Develop and test independently |
| 6 | Update mocks when the contract changes |
| 7 | Verify the actual API implementation |
| 8 | Run contract and integration tests |
This process reduces unnecessary dependencies and helps teams discover integration issues earlier.
Final Thoughts: Stop Waiting. Start Developing in Parallel!
In modern software development, waiting for dependent APIs can slow down the entire engineering team.
API mocking provides a practical solution.
It allows:
- Frontend teams to build without waiting for backend services.
- Backend teams to implement APIs independently.
- QA engineers to test different scenarios earlier.
- Developers to simulate errors and edge cases.
- CI/CD pipelines to run predictable tests.
But remember one important principle:
Mocks accelerate development. API contracts and integration testing protect correctness.
Use them together to build applications faster without sacrificing API quality.
Want to Learn More About API Mocking?
We've published a detailed guide covering API mocking concepts, static and dynamic mocks, OpenAPI-based mocking, WireMock, Postman, Playwright, parallel development, and contract testing.
Read the complete guide here: What Is API Mocking? How & When to Mock APIs – TotalShiftLeft.
Build faster. Test earlier. Develop together. Shift quality left!
About TotalShiftLeft
TotalShiftLeft is an AI-powered shift-left API testing platform that helps developers and QA teams generate API tests, identify bugs early, automate testing in CI/CD pipelines, and improve API quality through dashboards and reports.

