Topics
Recent articles

Product Engineering

How to Build the Front End Before the Backend API Is Ready

Use a small API contract and realistic network fixtures to start frontend development without treating mock success as integration evidence.

Table of Contents8 sections
Pixel art diagram contrasts a frontend mock demo with an integration check against the real API.
Build against agreed mock responses, then verify the actual provider before release.

You can build a frontend against fixtures before its API is deployed. But if the team has not agreed what an empty response, a missing field, or the next page means, a working demo can hide a disagreement instead of shortening the wait.

Quick solution:

Agree on the smallest request and response contract that affects the UI. Mock that HTTP boundary in development and tests. Keep the integration item open until the same client has exercised the real provider.

Start now: list view, loading, empty state, temporary failure
Agree first: null handling, pagination end, response status
Verify later: actual provider returns those behaviors in staging

The example below uses a fictional library loan list. It illustrates how to decide what to build, not a particular team’s release policy.

Decide what can start without the provider

A mock buys time when the remaining unknown is implementation or environment availability. It buys less when the frontend and backend are still deciding what the product does. A list layout does not need a deployed service. A renewal flow does need agreement on whether overdue loans are eligible, whether the operation completes immediately, and what the screen should show if the service accepts a request but cannot confirm its result.

Separate three situations. If the behavior is known and the wire format is agreed, implement the frontend against a mock. If the behavior is agreed but the format is uncertain, prototype layout and surface one sample payload for joint review before committing the adapter. If the unresolved policy changes what the user can do, split the stable part and keep the dependent behavior out of the current delivery forecast. The one-week backlog refinement routine shows how to split around a user outcome and record the owner and deadline for what remains unknown.

Treat a mock prototype as disposable if path, schema, and product behavior are all moving. It can answer a design question, such as whether the list is readable, without becoming a commitment to how the service behaves. Name that purpose in reviews. The phrase “UI demo using scenarios we wrote” is clearer than “the feature works” and helps people ask the right follow-up question.

Agree on the minimum contract for one screen

For the loan list, write one endpoint with request inputs, the success shape, and the exceptions that change rendering. Describe which fields are required, which permit null, and which can be omitted. A type in the UI repository alone does not answer these questions unless the provider has agreed to honor it. Put examples next to the shared spec and attach a reviewer from each side.

GET /v1/library/loans?cursor=<opaque value>
No cursor means first page. Send cursor only when one is present.
200: items array and required nextCursor (string or null).
Item: required id and title strings; dueAt is a date-time string or null.
401: sign-in is required. 503: temporary service failure.

In the sample, an empty array is a successful read with nothing to display, while a temporary failure means the availability of items is unknown. The client must not present “no loans” for both. A null due date gets a distinct label, “Due date unavailable,” rather than being parsed into a date or displayed as already overdue. A null cursor ends paging; the client should not try to interpret a non-null cursor or infer a terminal page from the number of rows.

A valid fictional first-page response with one item could be:

{
  "items": [{"id": "loan-101", "title": "Intro to Field Botany", "dueAt": null}],
  "nextCursor": "demo-page-2"
}

The token is an example value, not a counter the frontend should generate. The first-page fixture in the broader matrix can contain two items to exercise list append behavior.

An OpenAPI document can express paths, parameters, response bodies, schemas, and examples. Some behavior still needs a sentence, such as what an interrupted paging request means to someone who already sees the first page. Describe the wire agreement in the spec and the visible behavior in the story. That helps either team tell which kind of change needs a new review.

Mock the same HTTP boundary the real client uses

Put the substitution at the network boundary where practical: the view talks to its normal API client, and a test handler supplies a response for the requested method and route. The client still builds query parameters, parses data, and maps errors through the code it will use with the real service. Mock Service Worker is one option for web projects that need request interception. The same principle applies if your stack uses a local stub server.

A fixture is sample data, such as a first-page JSON file. A handler adds behavior: it decides when that fixture applies, which status to return, and whether a response should be delayed for a loading-state test. Verify the outgoing route and the expected query parameter in the test. If every request returns the same successful data regardless of its cursor, the test can pass while the client ignores paging entirely.

Avoid adding mock-specific code to the screen if you can drive it through the same adapter. Check the setup fails clearly for unhandled requests to the mocked API in the test environment; otherwise a misspelled path may go to a real network by accident or silently return a fallback. Keep mock startup scoped to local development or test harnesses rather than wiring it into the production entry point. Test and review that the normal release build is not using fixtures or an interception layer.

Use a fixture matrix that can catch real mistakes

Start small. A happy response proves the interface can show data with a particular shape. It does not test the empty state, the replacement of a failed page, or preservation of content during retry. Pick examples whose outcomes differ, including one where a plausible shortcut would produce a visible bug.

Scenario Response or condition User-visible check
First page with more rows Two loans and non-null nextCursor Rows render; requesting more sends the returned cursor.
Final page One loan and nextCursor null Row appends; no further page is requested.
Empty first page 200, no items, nextCursor null Show the empty state rather than an error.
Unknown due date A loan has dueAt null Show the unavailable label, not a date.
First page unavailable HTTP 503 Show a retry affordance, not an empty list.
Next page unavailable HTTP 503 after the first page Keep visible rows and retry only the missing page.

Authentication and transport errors deserve separate cases when a screen can show them. Verify that the sign-in result comes from the app’s agreed sign-in handling, not from the fixture pretending that sign-in happened. For loading, arrange a controlled delayed response and check that the screen shows progress before data arrives. Do not rely on waiting an arbitrary number of seconds for a test to transition.

A practical acceptance example is to send a successful first page, fail the next page, then allow the next page to succeed. Verify that the screen keeps the earlier rows, asks for the same cursor on retry, and does not append the first page a second time. This one test can catch mistakes in the boundary, state management, and UI. It does not prove that the actual service issues cursor tokens the same way.

Keep any malformed-response tests separate from examples the provider promises to send. Suppose a body has items but omits nextCursor. Under this sample contract, that is a violation, not a normal final page. If the application deliberately preserves the rows and stops paging under that condition, make this a resilience test with an observable diagnostic. Do not quietly change the expected contract to match a forgiving UI. Otherwise the release check might miss an API defect that makes valid results unreachable.

One way to keep the examples useful is to put the route, status, and body in each scenario record and choose a fixture by name in local development. That lets someone else reproduce a paging failure without editing the client or waiting for the service to fail. Use synthetic identifiers and varied values so every record does not look interchangeable. A fixture that switches from one state to another should reset after the test, so a different execution order does not change which state a subsequent test receives.

Review drift before it turns into a staging surprise

A hand-built fixture can drift from the shared contract. In review, treat edits to status codes, presence of fields, nullability, and paging rules as contract changes, even if they look small in a diff. Keep a contract version or a revision identifier beside the fixture set. Update its schema and examples together. If you validate fixtures against a schema in CI, ensure the schema itself is the shared revision rather than a UI-only copy that can diverge.

Schema validation answers whether an example is structurally allowed. It does not guarantee that the provider will produce it or that the UI handles the semantics correctly. For instance, a field can allow null without explaining when a due date is legitimately unavailable. Bring that example into provider review. If the provider would never emit it for an active loan, agree whether to change the fixture or make the fallback behavior an explicit defensive test.

When teams have the need and tooling, Pact’s consumer-driven approach pairs a consumer expectation with a provider verification step. This is useful if changes move independently and breaking assumptions are expensive. It is not the same as calling one handmade mock from a UI test. Start with the shared examples and provider-side checks if introducing a framework would cost more than the flow warrants. Keep a record of which provider revision was checked.

Record what still needs a real integration run

When the API is available, switch off interception in the integration environment and run the normal client against the intended provider. Confirm the client actually reached the provider and used the expected build or revision. Exercise a normal read, the empty state, and the relevant failure or pagination path. Where a real dependency failure is impractical to reproduce, use an approved controlled fixture or sandbox configuration for that specific behavior, and label which boundary was simulated.

A mocked run cannot show that staging credentials are configured, that cross-origin policies work as expected, that the provider reads the same records, or that both sides agree on how cursor pagination behaves across multiple requests. Provider contract verification also does not replace all of those deployment checks. Use different lanes in the report: client behavior with mocks, provider verification against the shared expectations, and real integration evidence. The SIT coverage guide explains how to report evidence by endpoint, scenario, and candidate without collapsing the lanes.

If the first integration run exposes drift, determine whether the contract, the consumer, or the provider needs to change. Avoid a quick UI patch that accepts two incompatible formats unless the team has chosen a temporary compatibility path and agreed when to remove it. Keep the fixture that exposed the issue as a regression case where useful. Record any new readiness decision against the candidate that was actually tested.

Hand off in terms of work still open

A useful update says which UI behaviors are implemented, which examples have been agreed, and what evidence is missing. Do not report one undifferentiated “done” state if the next team needs to finish the provider and then run the integration suite. If the provider misses its intended date, keep the original smaller delivery slice visible and clarify what will wait rather than extending the promise silently.

Frontend: list, empty state, paging retry pass against contract revision 3.
Provider: contract revision 3 reviewed; staging implementation pending.
Next: run the normal client against staging and record results for both page requests.
Release: not ready for this capability until integration evidence exists.

This handoff works even if the work is tracked in a single story, as long as the report makes the evidence visible. A team might track “frontend implemented” and “integration verified” separately within its workflow; it should use its own Definition of Done consistently rather than declaring the whole feature done from a mocked run.

The mock is worth building when it lets the team practice the real interaction earlier. Keep its name and its limits visible, so a green local test reduces uncertainty without hiding the work still left.

You Might Also Like

View all articles