Examples

Display code examples in a sticky right sidebar

Examples components display code blocks in a sticky right sidebar on desktop, keeping reference code visible while users scroll through your documentation. On mobile, they render as regular inline code blocks.

RequestExample

Use RequestExample to show API request code. Multiple code blocks create tabbed views.

curl -X POST https://api.example.com/users \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "email": "john@example.com"}'

Usage:

<RequestExample>
```bash cURL
curl -X POST https://api.example.com/users \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "email": "john@example.com"}'
```
</RequestExample>

ResponseExample

Use ResponseExample to show API responses. Include a status code and description after the language identifier.

{
  "id": "usr_123",
  "name": "John Doe",
  "email": "john@example.com",
  "created_at": "2024-01-15T10:30:00Z"
}

Usage:

<ResponseExample>
```json 200: Success
{
  "id": "usr_123",
  "name": "John Doe",
  "email": "john@example.com",
  "created_at": "2024-01-15T10:30:00Z"
}
```
</ResponseExample>

The status code determines the indicator color:

  • Green - 2xx success codes
  • Blue - 3xx redirect codes
  • Amber - 4xx client errors
  • Red - 5xx server errors

Multiple Languages

Add multiple code blocks to create a tabbed interface:

curl -X GET https://api.example.com/users/123 \
  -H "Authorization: Bearer $TOKEN"

Usage:

<RequestExample>
```bash cURL
curl -X GET https://api.example.com/users/123 \
  -H "Authorization: Bearer $TOKEN"
```

```python Python
import requests

response = requests.get(
    "https://api.example.com/users/123",
    headers={"Authorization": f"Bearer {TOKEN}"}
)
user = response.json()
```

```javascript JavaScript
const response = await fetch("https://api.example.com/users/123", {
  headers: {
    "Authorization": `Bearer ${TOKEN}`
  }
});
const user = await response.json();
```
</RequestExample>

Multiple Response Codes

Show different response scenarios with separate tabs:

{
  "id": "usr_123",
  "name": "John Doe",
  "email": "john@example.com"
}

Usage:

<ResponseExample>
```json 200: Success
{
  "id": "usr_123",
  "name": "John Doe",
  "email": "john@example.com"
}
```

```json 400: Bad Request
{
  "error": "validation_error",
  "message": "Email is required"
}
```

```json 404: Not Found
{
  "error": "not_found",
  "message": "User not found"
}
```
</ResponseExample>

Combined Usage

For API documentation, use both components together. The request appears above the response in the sidebar:

curl -X POST https://api.example.com/orders \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "product_id": "prod_456",
    "quantity": 2
  }'
{
  "id": "ord_789",
  "product_id": "prod_456",
  "quantity": 2,
  "status": "pending",
  "created_at": "2024-01-15T10:30:00Z"
}

Usage:

<RequestExample>
```bash cURL
curl -X POST https://api.example.com/orders \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "product_id": "prod_456",
    "quantity": 2
  }'
```
</RequestExample>

<ResponseExample>
```json 201: Created
{
  "id": "ord_789",
  "product_id": "prod_456",
  "quantity": 2,
  "status": "pending",
  "created_at": "2024-01-15T10:30:00Z"
}
```
</ResponseExample>

Status Code Formats

ResponseExample supports two formats for status codes:

```json 200: Success      // Colon separator
```json 400 - Bad Request // Dash separator

Both formats are parsed identically and display the status code with its description in the tab.