Frontend Prototyping Masterclass
Free Mock REST APIs for React Developers
Stop writing hardcoded mock JSON arrays in your React components. Connect directly to live, CORS-enabled endpoints with zero authentication.
1. TanStack Query (`useQuery`) with Products
Fetch and cache mock products with automatic loading and error states.
import { useQuery } from '@tanstack/react-query';
interface Product {
id: string;
title: string;
price: number;
category: string;
}
export function ProductList() {
const { data: products, isLoading, error } = useQuery<Product[]>({
queryKey: ['products'],
queryFn: async () => {
const res = await fetch('https://gen-endpoint.com/api/products');
if (!res.ok) throw new Error('Network error');
return res.json();
},
});
if (isLoading) return <div>Loading products...</div>;
if (error) return <div>Error loading catalog.</div>;
return (
<ul>
{products?.map((p) => (
<li key={p.id}>{p.title} - ${p.price}</li>
))}
</ul>
);
}2. SWR Data Fetching with User Management
Simulate optimistic revalidation and profile lookups with `/api/users`.
import useSWR from 'swr';
const fetcher = (url: string) => fetch(url).then((r) => r.json());
export function UserProfile() {
const { data, error, isLoading } = useSWR(
'https://gen-endpoint.com/api/users',
fetcher
);
if (isLoading) return <div>Loading users...</div>;
if (error) return <div>Failed to load users.</div>;
return (
<div>
<h3>Users ({data.users.length})</h3>
{data.users.map((u: any) => (
<p key={u.id}>{u.name} ({u.email})</p>
))}
</div>
);
}3. Mock Login Mutation & Form Handling
Test login forms, JWT token storage, and feedback toasts using `/api/auth/login`.
async function handleLogin(email: string, pass: string) {
const res = await fetch('https://gen-endpoint.com/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password: pass }),
});
const data = await res.json();
if (res.ok) {
localStorage.setItem('auth_token', data.token);
alert(`Welcome back, ${data.user.name}!`);
} else {
alert(data.error || 'Login failed');
}
}Recommended APIs for React Prototypes
Shopping Cart API
Session-based cart with add, update, and total calculations.
File Upload API
Test multipart drag-and-drop file inputs with progress states.