# Playground

Source: https://watership.ca/api-docs/docs/reference/playground

The panel that sends a request to one endpoint from its reference page. Every element on it, what it does, its default, and what changes when you use it.

The playground lets you build a request to one endpoint, send it, and read the response without leaving the docs. To open it, go to an endpoint page under **Endpoints** in the sidebar, such as [Check text](https://watership.ca/api-docs/docs/reference/api/checks/check-text), and select **Try in playground** beside the method and path.

The playground opens over the page, and on a narrow screen it fills the screen. It has four regions, read from the top: the title bar, the address bar, the request inputs on the left, and the request code and response on the right. On a narrow screen the inputs and the response share one space, and a **Request** and **Response** switch under the address bar chooses which one shows.

**Who can see or change it.** The playground runs in your browser. Anyone who can open the docs can use it, and nobody else sees what you enter or what comes back. A request goes only to the server you choose in the address bar. With the local mock server, nothing leaves your computer. The tables below say which values your browser keeps, and for how long.

## Title bar [#title-bar]

| Label | What it does | Default | When you use it |
|---|---|---|---|
| The endpoint name, such as **Check text** | Names the endpoint the playground sends to. | The endpoint of the page you opened it from | It's a heading, not an input. To try another endpoint, close the playground and open it from that endpoint's page. |
| **Example** | Lists the named request examples in the spec for this endpoint. Only **Check text** has them: **Check a Markdown draft** and **Report errors only**. Other endpoints don't show this list. | **Check a Markdown draft** | The request inputs are replaced with the example's values, including anything you changed in the body. |
| Close (×) | Closes the playground. | None | The page comes back. Your inputs and the last response stay until you leave or reload the page, so they're still there when you open the playground again. |

## Address bar [#address-bar]

| Label | What it does | Default | When you use it |
|---|---|---|---|
| Method, such as **POST** or **GET** | Shows the HTTP method of the endpoint. | The endpoint's method | It can't be changed. |
| Server URL, such as `http://127.0.0.1:4010` | Opens the **Server URL** list, which has the servers in the spec: `http://127.0.0.1:4010`, the local mock server, and `https://api.watership.ca`, the planned hosted service. | `http://127.0.0.1:4010` | Requests go to the server you choose. Your browser saves the choice and uses it on every endpoint page, including on later visits. The hosted service isn't live, so a request to it fails. |
| Path, such as **/v1/checks** | Shows the endpoint's path. A path parameter, such as `rule_id` in `/v1/rules/{rule_id}`, appears as a box inside the path. The box and the parameter's row under **Path** hold the same value. | The path from the spec, with each path parameter set to the spec's example, such as `term-please` | The value you enter goes into the request address and the request code. |
| **Send** | Sends the request. The button shows its shortcut: **Ctrl ↵** (Ctrl+Enter), or **⌘ ↵** on a Mac. | None | Your browser sends the request to the selected server, and the response region shows the result. The response region is dimmed until the response arrives. When it arrives, focus moves to the response, so a screen reader reads it and the keyboard continues from there. On a narrow screen, the switch changes to **Response**. |

## Request inputs [#request-inputs]

The left side lists every input the endpoint takes, in sections. A section appears only if the endpoint uses it.

### Authorization [#authorization]

| Label | What it does | Default | When you use it |
|---|---|---|---|
| **Authorization**, with **apiKey** | Names the section and the security scheme in the spec. | None | It's a heading, not an input. |
| **Authorization** field, with **header** | Holds the value of the `Authorization` header. Enter your key after `Bearer `. The mock server accepts any key, such as `wsk_test_example`. | `Bearer ` with no key | The header in the request code changes to match. Your browser keeps the value for this tab, so it's filled in on every endpoint page until you close the tab. With no key, the mock server answers `401 Unauthorized`. |

### Path, Query, and Body [#path-query-and-body]

**Path** holds the path parameters, **Query** the query parameters, and **Body** the JSON request body. **Path** and **Query** show how many parameters they hold, such as **7** on [List rules](https://watership.ca/api-docs/docs/reference/api/rules/list-rules). Only **Check text** has a **Body**, with these controls in its heading:

| Label | What it does | Default | When you use it |
|---|---|---|---|
| **application/json** | Shows the content type of the body. | `application/json` | It can't be changed. |
| **Form** | Shows the body as one row per field. | Selected | The body appears as rows. |
| **JSON** | Shows the body as JSON text that you can edit. | Not selected | The body appears as JSON. Edits in either view change the same body, so **Form** shows what you changed in **JSON**. |

Each field or parameter is one row. The rows follow the spec, and the names match the [API reference](https://watership.ca/api-docs/docs/reference/api/checks/check-text) exactly.

| Label | What it does | Default | When you use it |
|---|---|---|---|
| Field name, such as **text** or **min_level** | Names the field. A red **\*** after the name marks a required field. | None | It's a label, not an input. |
| Field info (ⓘ) | Opens a card with the field's type, its description from the spec, and its limits, such as the 100,000-character limit on `text`. The card also opens while you hover over the icon. | Closed | The card opens. Select anywhere else to close it. |
| The value | Holds the field's value. A field with a fixed set of values, such as `format`, `min_level`, `mode`, or `tier`, opens a list of those values. A true-or-false field, such as `automated`, shows **true** and **false**. Other fields take text. | The selected example's value, or the spec's example for the parameter. Otherwise empty, or **Unset** for a list of values. | The request code changes to match. |
| Type, such as **string** or **integer** | Shows the field's type from the spec. | None | It's a label, not an input. |
| Unset (×) | Removes the field from the request. It appears on any optional field once it has a value. | None | The field is left out of the request, and the API uses its default. |

A list field, such as `groups`, shows **Not set**, **1 item**, or the number of items, beside its type, **array&lt;Group&gt;**. Selecting it opens the list in place of the other inputs:

| Label | What it does | Default | When you use it |
|---|---|---|---|
| Back (←) and the path, such as **Body › groups** | Returns to the full list of inputs. Selecting **Body** does the same. | None | The full list comes back, and the field shows how many items it has. |
| **Unset** | Removes the whole list from the request. | None | The field is left out, and the API runs every group. |
| Item, such as **[0]** | Holds one value in the list. | The first allowed value, such as `voice`. Opening an empty list adds one item. | The request code changes to match. |
| Remove item (trash can) | Removes that item. | None | The items after it move up. |
| **Add item** | Adds another item. | None | A new row appears at the end. |

## Request code [#request-code]

The top of the right side shows the request you've built, as code you can run somewhere else.

| Label | What it does | Default | When you use it |
|---|---|---|---|
| **Request** | Names the region. | None | It's a heading, not an input. |
| Language, such as **cURL** | Chooses the language of the code: **cURL**, **JavaScript**, **Go**, **Python**, **Java**, **C#**, or **Rust**. | **cURL** | The code changes to that language. Your browser keeps the choice for this tab, and the code samples on the endpoint pages use it too. |
| Copy code (clipboard) | Copies the code, including your key. | None | The icon changes to a check mark to confirm the copy. |

## Response [#response]

The bottom of the right side shows the spec's example responses until you send a request, then the real response.

### Before you send [#before-you-send]

| Label | What it does | Default | When you use it |
|---|---|---|---|
| **Response** | Names the region. | None | It's a heading, not an input. |
| Status codes, such as **200**, **400**, and **429** | Shows one tab for each response the spec documents for this endpoint. | **200** | The description and the example change to that status. |
| Example list | Chooses between examples when one status has more than one, such as the two `400` examples for **Check text**. It doesn't appear otherwise. | The first example | The example changes. |
| Description, such as "The check ran. The findings may be empty." | Says what the status means for this endpoint, from the spec. | The `200` description | It changes with the status tab. |
| Example body, with Copy code | Shows the example response from the spec. | The first `200` example | Copy code copies it. |

The examples are the same ones the mock server responds with. For **Check text**, the `200` example is the real check engine's output, generated when the docs are built, for the **Check a Markdown draft** example.

### After you send [#after-you-send]

| Label | What it does | Default | When you use it |
|---|---|---|---|
| Status, such as **200 OK** or **400 Bad Request** | Shows the status code and its name. Its dot is green for a success, amber for a `4xx` code, and red for a `5xx` code. | None | It's a label, not an input. |
| Time and size, such as **25 ms · 3.8 kB** | Shows how long the request took and how large the response body is. It's hidden when the response region is narrow. | None | It's a label, not an input. |
| **Body** | Shows the response body. JSON is formatted. | Selected | The body appears. |
| **Headers**, with a count | Shows the response headers, such as `Watership-Release` and the `RateLimit-` headers. The count is the number of headers. | Not selected | The headers appear in place of the body. |
| Download | Saves the response body as a file. | None | Your browser downloads the file. |
| Clear (×) | Removes the response. | None | The example responses come back. |

If a request gets no response at all, the region shows **Request failed** and a message that suggests checking the server URL. The usual causes are that the mock server isn't running, or that `https://api.watership.ca` is selected.

## Tasks that use the playground [#tasks-that-use-the-playground]

- [Try an endpoint in the playground](https://watership.ca/api-docs/docs/tasks/try-an-endpoint)
- [Run the mock server](https://watership.ca/api-docs/docs/tasks/run-the-mock-server), which the playground sends to by default
