Playground API
DocsStatsBlogStudio
Documentation Tree
Technical BlogFeature Deep Dives
  • Introduction
  • Quickstart
    5 min
  • How It Works
  • Recipes & Cookbooks
  • Platform Comparisons
  • Real-World Showcase
  • Interactive Studio
    Studio
  • GraphiQL IDE
    IDE
  • Session Quotas & Activity
  • Network Chaos Simulator
  • Atomic Sandbox Reset
  • Overview & Models
    Hub
  • Users Resource
  • Posts Resource
  • Comments Resource
  • Todos Resource
  • Custom Collections
    Custom
  • Multipart File Uploads
    Upload
  • Dynamic SVG Avatars
    SVG
  • Image Thumbnails
    CDN
  • Relational Filtering
  • Full-Text Search
  • Dynamic Sorting
  • Offset Pagination
  • Cursor Pagination
    Scroll
  • CSV & Excel Export & Import
    IO
  • Custom Collections
    CRUD
  • Overview & Architecture
    Hub
  • JWT Auth Flow
  • Refresh Token Rotation
    Mutex
  • RBAC Permission Matrix
    Roles
  • Expiry Simulation
  • Clock Skew Drift
  • Password Recovery Loop
  • Dual-Mode Sandboxing
  • GraphiQL IDE
    IDE
  • Relational Queries
  • Stateful Mutations
  • Realtime Subscriptions
  • Overview & Flowcharts
    Hub
  • Hosted Checkout
    Stripe
  • Payment Intents API
  • 3DS Challenge Modal
    Modal
  • Customers Vault
  • Charges & Refunds
  • Test Cards Catalog
  • Overview & Channels
    Hub
  • Virtual Email Mailbox
    Mailtrap
  • Virtual SMS Terminal
    Phone
  • In-App Notifications
  • Message Dispatcher
  • Realtime Studio
    Studio
  • Native WebSocket (/ws)
  • Socket.io Gateway
  • Presence & Echo Bot
  • Server-Sent Events (SSE)
    SSE
  • Analytics Telemetry
  • Webhook Subscriptions
  • HMAC SHA-256 Signatures
  • Delivery Logs
  • Manual Retry Simulator
  • Network Latency Delay
  • HTTP Status Codes
  • Rate-Limit Simulator
    429
  • Flaky Network & Jitter
    Chaos
  • Session Quotas & Activity
  • JSON Snapshots
    JSON
  • Headless CI/CD Testing
    CI
  • Mobile QR Code Sync
  • System Metrics & Health
  • Atomic Sandbox Reset
  • Official TypeScript SDK
  • Multi-Language Generators
  • DevTools Extension
  • OpenAPI 3.1 Spec
    JSON
  • Postman Collection v2.1
  • Bruno Collection
  • Insomnia Workspace
  • TypeScript .d.ts
    .d.ts
  • AI Prompt Rules
    Rules
  • Context Index (llms.txt)
  • Full Schema (llms-full.txt)
  • Manifest (product.json)
  • All Feature Articles
    Blog
  • React CRUD Without Backend
    Deep Dive
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE Guide
Technical Blog
Articles

In-depth articles explaining stateful mock APIs, WebSockets, payments, and frontend resilience.

Read Articles
PreviousHow It Works
NextPlatform Comparisons
Fullstack Cookbooks

Integration Recipes & Cookbooks

Production-tested patterns and boilerplate code to connect Playground API to TanStack Query, Next.js 15 Server Actions, Axios, Vue 3, Svelte 5, and Playwright E2E suites.

Select Your Stack

recipe-tanstack
1
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2
3
interface Post {
4
id: number;
5
title: string;
6
body: string;
7
user_id: number;
8
}
9
10
// 1. Fetch posts with credentials for isolated visitor session
11
export function usePosts(page = 1, limit = 10) {
12
return useQuery({
13
queryKey: ['posts', { page, limit }],
14
queryFn: async (): Promise<Post[]> => {
15
const res = await fetch(${'https://playground.nileslabs.com/api/v1'}/posts?_page=${page}&_limit=${limit}, {
16
credentials: 'include', // Persists HMAC session cookie
17
});
18
if (!res.ok) throw new Error('Failed to load posts');
19
const json = await res.json();
20
return json.data || json;
21
},
22
});
23
}
24
25
// 2. Stateful create mutation with optimistic updates
26
export function useCreatePost() {
27
const queryClient = useQueryClient();
28
29
return useMutation({
30
mutationFn: async (newPost: Omit<Post, 'id'>): Promise<Post> => {
31
const res = await fetch('https://playground.nileslabs.com/api/v1/posts', {
32
method: 'POST',
33
headers: { 'Content-Type': 'application/json' },
34
credentials: 'include',
35
body: JSON.stringify(newPost),
36
});
37
if (!res.ok) throw new Error('Mutation failed');
38
return res.json();
39
},
40
// Invalidate and refetch posts query immediately
41
onSuccess: () => {
42
queryClient.invalidateQueries({ queryKey: ['posts'] });
43
},
44
});
45
}
46
47
// 3. Stateful delete mutation
48
export function useDeletePost() {
49
const queryClient = useQueryClient();
50
51
return useMutation({
52
mutationFn: async (id: number) => {
53
const res = await fetch(${'https://playground.nileslabs.com/api/v1'}/posts/${id}, {
54
method: 'DELETE',
55
credentials: 'include',
56
});
57
if (!res.ok) throw new Error('Delete failed');
58
return res.json();
59
},
60
onSuccess: () => {
61
queryClient.invalidateQueries({ queryKey: ['posts'] });
62
},
63
});
64
}

Integration Best Practices

Always Send Credentials

When querying from a browser, always specify credentials: 'include' (or Axios withCredentials: true) to ensure the HMAC session cookie is preserved.

Deterministic CI Headers

In automated test runners (Cypress, Playwright), use X-Playground-Identity: [test-id]. This guarantees parallel test workers never interfere with each other.

Cleanup After Test Suites

In test afterEach or beforeEach hooks, issue a DELETE /session/reset to ensure each test executes against clean baseline data.

Want to see these recipes in an end-to-end production application?

Check out the featured React 18 E-Commerce store demo with cart, JWT auth, and dynamic products.

View Showcase Demo