api-playground
Describe an API request without executing it
interactive 1.0.0 Apache-2.0
Install
docsloth component add @docsloth/api-playground@1.0.0 \
--registry https://registry.docsloth.devRun it in a project that has a docsloth.config.json (docsloth init writes one). The docsloth CLI is not on npm yet: it runs from a checkout of the Docsloth engine, and the quickstart shows the setup. Every official component already renders in Docsloth sites; installing one vendors its props schema and specification and pins this exact version and digest.
What the CLI checks
docsloth component add reads this entry from index.json, recomputes the package digest from the manifest and the digest of every file, and writes nothing if one differs.
index.json, lines 61–7861 {62 "name": "@docsloth/api-playground",63 "version": "1.0.0",64 "kind": "block",65 "description": "Describe an API request without executing it",66 "license": "Apache-2.0",67 "engine": ">=1 <2",68 "publisher": "docsloth",69 "digest": "sha256:057f7e251512acc2d0e98c0d338e39c6b84afafe5b4d03542eb56021f8514bad",70 "blocks": [71 "api-playground"72 ],73 "capabilities": [74 "render.html"75 ],76 "manifest_path": "packages/@docsloth/api-playground/1.0.0/manifest.json",77 "files_base": "packages/@docsloth/api-playground/1.0.0/files"78 },Trust signals
- Runtime trust class (catalog)
- interactive. Responds to the reader inside the page, such as switching tabs or filtering, with no network access and no secrets.
- Install trust class
- interactive, derived from the declared
render.html. This is the classdocsloth component addanddocsloth component listreport; it installs under the default policy, with no trust policy. - Package
@docsloth/api-playground, version1.0.0- Package digest
sha256:057f7e251512acc2d0e98c0d338e39c6b84afafe5b4d03542eb56021f8514bad- Files
- 2 files, each pinned by its own sha256 digest (listed under Package files)
- Capabilities declared
render.html. A declaration, never a grant; every official package declares the same.- Publisher
docsloth, a publisher id rather than a verified identity- Licence
Apache-2.0- Engine range
>=1 <2- Index signature
- Not signed. Digests prove the bytes match the index, not who published them.
- Tools
- none
- Built from
packages/contracts/component-props/api-playground.schema.jsonandpackages/contracts/component-specs/api-playground.mdin docsloth-registry
Props
The props schema is packages/contracts/component-props/api-playground.schema.json; props it does not list are rejected.
| Prop | Type | Required | Notes |
|---|---|---|---|
method | string | yes | maxLength: 32; pattern: ^[A-Za-z][A-Za-z0-9-]*$ |
path | string | yes | maxLength: 500 |
baseUrl | string | no | maxLength: 500; pattern: ^https?:// |
auth | "none" | "bearer" | no | |
parameters | array<object> | no | |
requestBody | object | no | additionalProperties: false |
requestBody.contentType | string | no | maxLength: 200 |
requestBody.example | string | no | |
summary | string | no | maxLength: 500 |
Required: method, path.
Example props generated from the schema
{
"method": "GET",
"path": "/v1/pets",
"baseUrl": "https://api.example.com",
"auth": "none",
"parameters": [
{
"name": "limit",
"in": "query",
"required": true,
"description": "Max items",
"example": 10
}
],
"requestBody": {
"contentType": "application/json",
"example": "{\"name\":\"Rex\"}"
},
"summary": "Create a pet"
}Preview
Rendered by @docsloth/renderer from the example document block in the specification.
Document block
{
"type": "api-playground",
"props": {
"method": "POST",
"path": "/v1/pets",
"baseUrl": "https://api.example.com",
"auth": "bearer",
"summary": "Create a pet",
"parameters": [
{
"name": "limit",
"in": "query",
"required": false,
"description": "Max items",
"example": 10
}
],
"requestBody": {
"contentType": "application/json",
"example": "{\"name\":\"Rex\"}"
}
}
}Create a pet
POST /v1/pets
POST https://api.example.com/v1/pets?limit=10
Authorization: Bearer <token>
Content-Type: application/json
{"name":"Rex"}| name | in | required | description | example |
|---|---|---|---|---|
| limit | query | no | Max items | 10 |
Requests run in the host page. Nothing executes in the renderer.
This is the renderer's real HTML with this registry's styles. Links and controls in the preview are inactive.
Rendered HTML
<section class="ds-playground" data-component="api-playground" data-method="POST" data-auth="bearer" aria-label="POST /v1/pets API playground">
<p class="ds-playground-summary">Create a pet</p>
<p class="ds-playground-signature">
<span class="ds-method" data-method="POST">POST</span>
<code class="ds-playground-path">/v1/pets</code>
</p>
<pre class="ds-playground-example" aria-label="Example request">
<code>POST https://api.example.com/v1/pets?limit=10
Authorization: Bearer <token>
Content-Type: application/json
{"name":"Rex"}</code>
</pre>
<form class="ds-playground-form" method="dialog" data-ds-playground-form data-markdown-ignore="true" aria-label="Request builder">
<fieldset class="ds-playground-fields">
<legend>Parameters</legend>
<div class="ds-playground-field">
<label for="b-param-0">limit (query)</label>
<input id="b-param-0" name="limit" type="text" value="10" aria-describedby="b-param-0-hint">
<p class="ds-playground-hint" id="b-param-0-hint">Max items</p>
</div>
</fieldset>
<fieldset class="ds-playground-fields">
<legend>Request body (application/json)</legend>
<label for="b-body">Body (application/json)</label>
<textarea id="b-body" name="body" rows="4">{"name":"Rex"}</textarea>
</fieldset>
<button type="submit" class="ds-playground-run" data-ds-playground aria-label="Run request">Run</button>
</form>
<table class="ds-playground-params">
<thead>
<tr>
<th>name</th>
<th>in</th>
<th>required</th>
<th>description</th>
<th>example</th>
</tr>
</thead>
<tbody>
<tr>
<td>limit</td>
<td>query</td>
<td>no</td>
<td>Max items</td>
<td>10</td>
</tr>
</tbody>
</table>
<p class="ds-playground-note">Requests run in the host page. Nothing executes in the renderer.</p>
</section>Specification
From packages/contracts/component-specs/api-playground.md.
Contract
Packaged: this block ships as @docsloth/api-playground@1.0.0 — an installable component package (kind block, capability render.html, Apache-2.0) whose production props schema is packages/contracts/component-props/api-playground.schema.json and whose catalog entry is in packages/contracts/component-catalog.json. No protocol manifest fixture is published (manifest_fixture: null): the fixture models a packaged protocol runtime this block does not have.
Intended behavior
Build a request from an OpenAPI-style operation: method, path, optional base URL, auth mode, typed parameters and an optional request body. The example request line and parameter table are generated server-side from props, so the same request exists as inert HTML text and as an agent-readable http fence. The form is progressive enhancement only.
Failure and fallback
A missing or invalid method/path, a non-array parameters, a parameter without a name, or a non-object requestBody degrades the whole block to the labelled fallback. An unknown auth value and a non-http(s) baseUrl degrade in place (ignored) instead of taking out the block.
Required acceptance cases
Opening the page, reading the Markdown twin or submitting the form must never perform a network request, read a credential or execute renderer-supplied code without a host-provided handler. Also test empty data, missing parameters, a bearer example, browser without JS, mobile 360px, keyboard navigation, dark mode and an explicit constrained agent tool call. The server independently authorizes capability requests; a package manifest cannot grant authority.
Data and maintenance
Data bindings resolve from a specific publication/release vector and permitted fact/evidence graph. Configuration edits create versioned component patches. Update invalidation uses dependency IDs, never indiscriminate whole-page regeneration. Human-owned props survive automatic updates unless invalidated with an explicit conflict. Missing optional resources leave an honest inert/readable fallback, not a broken page or fake success.
Cost and tools
Pure/local interaction must never invoke a model by accident. Running a request is a host capability: the renderer emits no script, no inline handler and no action, and the form is method="dialog" so submitting it without a host handler never navigates or sends its fields (a form without an action would submit them to the current URL); it never receives raw credentials. Any model, remote query or executor call must reserve approved budget before dispatch. The component may call only named tools in its signed manifest with valid typed inputs.
Native renderer block
packages/renderer renders an api-playground block from the document IR. HTML emits an accessible <form> (data-ds-playground-form) whose inputs are <label for=…>-wired and described by their hints, a Run button carrying data-ds-playground, a server-side example request line and a parameter table. Markdown emits the same request as a fenced http example plus the same parameter table — the agent fallback — and repeats the progressive-enhancement note. Running requests is the host page's responsibility; nothing executes in the renderer.
Native block props
| prop | type | required | behaviour |
|---|---|---|---|
method | string | yes | HTTP method token, normalised to upper case; missing or non-token values degrade to the fallback. |
path | string | yes | Path (a missing leading / is added) or absolute URL; whitespace, quotes and angle brackets degrade to the fallback. |
baseUrl | string | no | http(s) origin prefixed to the example URL; any other value is ignored. |
auth | 'none' | 'bearer' | no | bearer adds an Authorization: Bearer <token> line to the example; any other value is ignored. |
parameters | {name, in, required?, description?, example?}[] | no | One labelled input plus one table row per parameter; a wrong shape degrades to the fallback. |
requestBody | {contentType, example?} | no | Adds a Content-Type line and body text; a wrong shape degrades to the fallback. |
summary | string | no | Visible description of the operation, mirrored in Markdown. |
The form is interface-only chrome and is marked data-markdown-ignore; because hiding a focusable control would break assistive technology it stays in the accessibility tree. The parameter table, example request and note are content and are never ignored.
Example
{
"type": "api-playground",
"props": {
"method": "POST",
"path": "/v1/pets",
"baseUrl": "https://api.example.com",
"auth": "bearer",
"summary": "Create a pet",
"parameters": [
{ "name": "limit", "in": "query", "required": false, "description": "Max items", "example": 10 }
],
"requestBody": { "contentType": "application/json", "example": "{\"name\":\"Rex\"}" }
}
}
Package files
Served under packages/@docsloth/api-playground/1.0.0/. The package digest covers manifest.json, which lists each file with its digest.
| File | sha256 digest | Bytes |
|---|---|---|
props.schema.json | sha256:e9a82c7d428fa7049f9c748c4b7f6d948e5ff98f9c21efdb6bcdb8d8b5c566a0 | 2594 |
spec.md | sha256:095413f0ecec2094925cadfc36678453e72a12b2412085d41b8574d208132b20 | 4989 |
Sources
| Source | Location |
|---|---|
| Markdown twin | https://registry.docsloth.dev/docs/api-playground.md |
| JSON metadata | https://registry.docsloth.dev/api/v1/components/api-playground.json |
| Specification | packages/contracts/component-specs/api-playground.md |
| Props schema | packages/contracts/component-props/api-playground.schema.json |
| Catalog | packages/contracts/component-catalog.json |