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
PreviousAtomic Sandbox Reset
NextMulti-Language Generators
Developer Toolkit

Official TypeScript SDK

An isomorphic, zero-dependency client library providing end-to-end type safety, automatic session identity persistence, intelligent retry backoff, and full autocomplete across browser, Node.js, and Next.js runtimes.

Installation

Add playground-api to your application with your favorite package manager:

terminal
npm install playground-api

Browser CDN Alternative: You can also load the client bundle directly via script tag from https://playground.nileslabs.com/api/v1/downloads/playground-api.js which exposes window.PlaygroundClient.

Client Initialization & Session Management

Initialize the client according to your application environment:

client.ts
1
import { PlaygroundClient } from 'playground-api';
2
3
// Browser client automatically forwards session cookies
4
const client = new PlaygroundClient({
5
baseUrl: 'https://playground.nileslabs.com/api/v1',
6
credentials: 'include', // Preserves mutations across user browser refreshes
7
});
8
9
// Fetch posts with type-safe query parameters
10
const { data, pagination } = await client.posts.list({
11
page: 1,
12
limit: 10,
13
sort: 'id',
14
order: 'desc',
15
});
16
17
console.log('Posts:', data);
18
console.log('Total available:', pagination.total);

Typed Resource Operations

Every standard API resource is exposed as a strongly typed submodule on the client:

posts-operations.ts
1
// 1. List with search, filtering, and pagination
2
const posts = await client.posts.list({
3
q: 'technology',
4
userId: 1,
5
page: 1,
6
limit: 5,
7
});
8
9
// 2. Fetch relational comments for a post
10
const comments = await client.posts.getComments(posts.data[0].id);
11
12
// 3. Create a stateful blog post
13
const created = await client.posts.create({
14
title: 'Shipping with Playground API',
15
body: 'Full-stack testing with zero backend friction.',
16
userId: 1,
17
});
18
19
// 4. Update and Delete
20
await client.posts.patch(created.id, { title: 'Updated Title' });
21
await client.posts.delete(created.id);

Error Handling & Validation Details

Failed HTTP calls throw typed PlaygroundApiError exceptions with status codes, error identifiers, and field-level validation details:

error-handling.ts
1
import { PlaygroundClient, PlaygroundApiError } from 'playground-api';
2
3
const client = new PlaygroundClient({ baseUrl: 'https://playground.nileslabs.com/api/v1' });
4
5
try {
6
await client.posts.get(999999);
7
} catch (error) {
8
if (error instanceof PlaygroundApiError) {
9
console.error('HTTP Status:', error.status); // 404
10
console.error('Error Code:', error.code); // 'RESOURCE_NOT_FOUND'
11
console.error('API Message:', error.message); // 'Post with id 999999 does not exist'
12
console.error('Validation Errors:', error.details); // Field-level error array if 422
13
} else {
14
console.error('Unexpected network failure:', error);
15
}
16
}

Need cURL, Python, or Go code instead?

Generate copy-pasteable request snippets in your language of choice.

View Code Generators