API Playground
ApiPlaygroundBlock uses a mockHandler pattern. It does not blindly send network requests (which usually fail due to CORS in documentation environments). Instead, you define exactly how the component should respond to different inputs, creating a safe, curated learning experience.mockHandler decides the response.API playground
A split-pane request builder.
- Pass
mockHandler - an async function — it receives the method, url, headers, params and body, and returns { status, timeMs, data } for the response pane to render.
defaultUrl- seeds the address bar the reader lands on.
Installation
New project? Follow the installation guide to set up Tailwind CSS, shadcn, the cn helper and lucide-react, register the @algorize-ui registry once, then copy your styles from the Themes page.
Install API Playground
components/ is written into your project. Copy any snippet from a Usage tab above and it runs.
Install dependencies
Step 1 installs this for you. Run it yourself only if you are adding API Playground to an existing project by hand. The cn helper and lucide-react are not listed — the installation guide covers them once for every component.
select is a component, not a package — the shadcn CLI installs it as source files.
Features & Core Capabilities
Split-Pane Architecture
Interactive dual-panel interface with real-time HTTP Request Builder on the left and Live JSON Response Viewer on the right.
CORS-Safe Mock Handler
Uses a client-side mockHandler async function to simulate network latency, dynamic endpoints, and custom status codes safely without CORS issues.
Full Header & Query Params Editor
Add, enable/disable, or remove HTTP headers and query parameters dynamically before executing API calls.
JSON Body Payload & Syntax Highlighting
Built-in raw JSON request body editor with syntax highlighting, automatic JSON formatting, error handling, and response timing metrics.
Best Practices & Guidelines
Usage Guidelines
Provide realistic mock handlers with simulated delays (e.g. 100ms - 500ms) to give users an authentic API testing experience directly inside your documentation.
Props Reference
| Prop | Type | Default | Description |
|---|---|---|---|
defaultUrl | string | "https://api.example.com/v1/users" | Initial API URL displayed in the request address bar. |
defaultMethod | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "GET" | Initial HTTP method selected in the method dropdown. |
color | ApiColor | "primary" | Accent color theme ("primary" | "indigo" | "rose" | "emerald" | "zinc" or custom hex). |
mockHandler | ApiMockHandler | undefined | Async function that receives request details and returns simulated API response data. |
className | string | undefined | Additional CSS classes applied to the root container. |
mockHandler Object Signatures
ApiPlaygroundRequest (passed to your function):ApiResponse (required return type):