The API Playground component renders a single, runnable endpoint inside your page. Readers fill in the parameters, hit Send, and see the actual HTTP response — without leaving the docs.
It's the building block behind the auto-generated OpenAPI reference. You can also drop a single playground into any page when you want a focused example.
Pro plan or higherExample#
Screenshot needed
screenshot of the rendered playground showing parameter form, Send button, response viewer
Source#
<APIPlayground
method="GET"
url="https://api.example.com/v1/users/{id}"
parameters={[
{ name: "id", type: "string", required: true, description: "User ID" }
]}
/>Props#
| Prop | Type | Description |
|---|---|---|
method | GET POST PUT PATCH DELETE | HTTP method |
url | string | Full URL with {path} placeholders for path params |
parameters | array | Array of { name, type, required, description } objects for path/query params |
body | object | JSON Schema for the request body (POST/PUT/PATCH only) |
headers | array | Header name/value pairs (Authorization is added automatically) |
auth | bearer, apikey, basic, none | Auth scheme. Defaults to project setting. |
Authentication#
The playground reads project-level auth config from Settings → API → Authentication. Readers see an "Add token" field above the request form; tokens are stored in browser local storage only — never sent to Dokly servers.
If you set auth="none" on a specific playground, the auth field is hidden — useful for public endpoints.
Body schema#
For POST/PUT/PATCH endpoints, define the body shape:
<APIPlayground
method="POST"
url="https://api.example.com/v1/users"
body={{
type: "object",
properties: {
name: { type: "string", description: "Full name" },
email: { type: "string", format: "email" }
},
required: ["name", "email"]
}}
/>The playground generates a form from the schema. Readers can also switch to "Raw JSON" mode to paste a body directly.
Response viewer#
The response panel shows:
- Status — color-coded (green for 2xx, yellow for 4xx, red for 5xx).
- Time — request duration.
- Headers — collapsible.
- Body — pretty-printed JSON with syntax highlighting. Auto-collapsed if longer than 50 lines.
If the API returns CORS errors, the playground shows a friendly error explaining why and links to your CORS configuration page.
CORS configuration#
For the playground to actually call your API, your API must allow requests from *.dokly.co (or your custom domain). Add to your CORS config:
Access-Control-Allow-Origin: https://docs.acme.com
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETEFor development, you can also add https://localhost:3000 and https://*.dokly.co.
When to use a single playground vs OpenAPI#
| Situation | Use |
|---|---|
| One or two endpoints in the middle of a guide | Single <APIPlayground> |
| Full API reference (10+ endpoints) | OpenAPI import |
The OpenAPI import is just a way to generate one playground per endpoint at scale. The component is the same.