Guides / Mobile

React Native

Mock Mobile User Profiles with Dynamic :id Routes

Use a hosted /v1/users/:id contract to build repeatable profile screens across simulators, emulators, physical devices, and preview builds.

Mockport Team · Updated September 28, 2026 · 13 min read

What you’ll build

  • A dynamic profile route with static JSON.
  • A typed React Native fetch helper.
  • Loading, offline, missing, and service-error states.
  • Repeatable fixtures for simulators and physical devices.

01

Define the dynamic mobile profile route

Create a mobile-profiles project and add GET /v1/users/:id. The dynamic path keeps one recognizable route in the workspace while your app requests resolved ids such as /v1/users/usr_123.

Paste a complete but compact static profile. Use invented names and an image URL you control. Every device receives the same JSON, making visual review consistent.

profile-response.json
{
  "id": "usr_123",
  "name": "Maya Chen",
  "handle": "@mayac",
  "bio": "Product designer and trail runner",
  "avatar": null
}
Practical note

Dynamic inputs resolve the URL; the response remains static. To review different content, create explicit fixture routes rather than assuming id-based data generation.

02

Resolve ids from navigation

Read the user id from navigation and encode it before composing the URL. Reject an absent id before making a request so a screen configuration error is not mistaken for a missing profile.

Keep the hosted domain in a public mobile environment variable. HTTPS lets simulators and physical devices reach it without depending on your laptop’s loopback address.

profile-api.ts
export type Profile = {
  id: string;
  name: string;
  handle: string;
  bio: string;
  avatar: string | null;
};

export async function fetchProfile(id: string): Promise<Profile> {
  const base = process.env.EXPO_PUBLIC_API_URL;
  if (!base || !id) throw new Error("PROFILE_CONFIG_MISSING");

  const response = await fetch(
    `${base}/v1/users/${encodeURIComponent(id)}`
  );

  if (!response.ok) throw new Error(`PROFILE_${response.status}`);
  return response.json() as Promise<Profile>;
}

03

Design loading and profile presentation

Render the screen shell immediately, then place a labeled progress indicator where the profile will appear. This preserves navigation context and avoids a blank screen while the request is active.

When data arrives, show the avatar or fallback, name, handle, and bio in a stable reading order. Include enough text to verify wrapping on narrow devices and at larger accessibility text sizes.

ProfileContent.tsx
import { ActivityIndicator, Text, View } from "react-native";

// Inside your screen:
if (loading) {
  return <ActivityIndicator accessibilityLabel="Loading profile" />;
}

return (
  <View>
    <Text accessibilityRole="header">{profile.name}</Text>
    <Text>{profile.handle}</Text>
    <Text>{profile.bio}</Text>
  </View>
);
  • Expose an accessible loading label.
  • Reserve avatar space to reduce layout movement.
  • Allow the bio to wrap at large text sizes.
  • Treat the handle as supporting text, not the only identity.

04

Separate offline, not-found, and service errors

A network exception may indicate the device is offline; an HTTP response means the endpoint was reached. Use connection information to distinguish genuine offline behavior from a service error.

Use a dedicated not-found route for an unknown id and a 503 scenario route for service-unavailable presentation. Preserve the requested id so testers know which state they are seeing.

profile-error-message.ts
export function profileErrorMessage(status: number | null) {
  if (status === null) return "Could not connect. Check your network.";
  if (status === 404) return "Profile not found.";
  if (status === 503) return "Profiles are temporarily unavailable.";
  return "Couldn’t load profile. Please try again.";
}
Practical note

A 503 response is not a simulation of losing network connectivity. Test offline behavior using the device or simulator’s network controls.

05

Account for simulator and device networking

A hosted project domain is reachable from iOS Simulator, Android Emulator, and physical devices with internet access. This avoids platform-specific loopback addresses used by local servers.

Confirm that the device can access HTTPS and the environment value is embedded in the active build. Rebuild or reload after changing the URL.

.env
EXPO_PUBLIC_API_URL=https://mobile-profiles.mockport.dev
  • Open the public endpoint from the device browser.
  • Confirm EXPO_PUBLIC_API_URL in the active build.
  • Use invented fixture data only.
  • Test portrait, landscape, and larger text settings.

06

Keep fixtures repeatable across reviews

Use memorable fixture routes for standard profiles, long-content checks, and missing states. Record their paths in test names and review notes.

Do not edit the shared standard fixture during a scheduled review. Add an explicit route when a second response is required, then keep fixtures static through the review cycle.

profile-fixtures.ts
export const profileFixtures = {
  standard: "/v1/users/usr_123",
  longContent: "/v1/fixtures/long-profile",
  missing: "/v1/users/not-found",
  serviceError: "/v1/users/service-error",
} as const;

Keep the contract predictable, then keep building.

Your mobile team now shares an HTTPS profile contract with known fixtures and complete interface states. Simulators and physical devices can review the same content without depending on one developer’s machine.

Put your next endpoint online in minutes.

Start a 14-day trial. Team workspaces are $9/month with 5 project domains, 15 routes per project, and up to 5 seats.

Start free trial →

Related guides