---
title: 请求与响应示例
description: 了解如何使用 RequestExample 和 ResponseExample 组件，通过 Acme 支持工单工作流记录 API。
api: GET /tickets/{ticket_id}
---

> **For AI agents:** the complete documentation index is at [llms.txt](/docs/llms.txt). Append `.md` to any page URL for its markdown version.

使用 `RequestExample` 和 `ResponseExample` 展示实际 API 用法，并将其与端点文档结合。组件支持多种语言、响应状态和内联说明。

## 示例：获取支持工单

此示例记录了 Acme Support API 的简单 `GET /tickets/{ticket_id}` 端点。

### 请求

使用参数字段描述端点所需的内容。代码示例显示在右侧边栏中。

<ParamField path="ticket_id" type="string" required>
  创建工单时返回的唯一工单标识符。
</ParamField>

<RequestExample>
```bash cURL
curl -X GET https://api.acme.com/v1/tickets/tkt_9S8L2 \
  -H "Authorization: Bearer $ACME_TOKEN"
```

```python Python
import requests

response = requests.get(
    "https://api.acme.com/v1/tickets/tkt_9S8L2",
    headers={"Authorization": f"Bearer {ACME_TOKEN}"}
)

ticket = response.json()
print(ticket["id"])
```

```javascript JavaScript
const response = await fetch("https://api.acme.com/v1/tickets/tkt_9S8L2", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.ACME_TOKEN}`,
  }
});

const ticket = await response.json();
console.log(ticket.id);
```

```go Go
package main

import (
  "fmt"
  "io"
  "net/http"
)

func main() {
  req, _ := http.NewRequest("GET", "https://api.acme.com/v1/tickets/tkt_9S8L2", nil)
  req.Header.Set("Authorization", "Bearer ACME_TOKEN")

  resp, _ := (&http.Client{}).Do(req)
  defer resp.Body.Close()

  body, _ := io.ReadAll(resp.Body)
  fmt.Println(string(body))
}
```

```ruby Ruby
require 'net/http'
require 'uri'
require 'json'

uri = URI("https://api.acme.com/v1/tickets/tkt_9S8L2")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer ACME_TOKEN"

response = http.request(request)
puts JSON.parse(response.body)
```

```csharp C#
using System.Net.Http;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer ACME_TOKEN");

var response = await client.GetAsync("https://api.acme.com/v1/tickets/tkt_9S8L2");
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
```

```java Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.acme.com/v1/tickets/tkt_9S8L2"))
    .header("Authorization", "Bearer ACME_TOKEN")
    .GET()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

```rust Rust
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = reqwest::Client::new();

    let response = client
        .get("https://api.acme.com/v1/tickets/tkt_9S8L2")
        .header("Authorization", "Bearer ACME_TOKEN")
        .send()
        .await?;

    let body = response.text().await?;
    println!("{}", body);

    Ok(())
}
```

```php PHP
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.acme.com/v1/tickets/tkt_9S8L2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ACME_TOKEN']);

$response = curl_exec($ch); curl_close($ch);

echo $response;
```
</RequestExample>

### 响应

使用响应字段记录 API 返回的最重要属性。

<ResponseField name="id" type="string" required>
  唯一工单标识符。
</ResponseField>

<ResponseField name="status" type="string">
  当前工单状态（`open`、`pending` 或 `resolved`）。
</ResponseField>

<ResponseField name="created_at" type="string">
  工单创建时间的 ISO 8601 时间戳。
</ResponseField>

<ResponseExample>
```json 200: OK
{
  "id": "tkt_9S8L2",
  "customer_id": "cus_2X9W8",
  "subject": "Export stuck on step 3",
  "priority": "high",
  "status": "open",
  "created_at": "2026-02-04T16:12:00Z"
}
```

```json 404: Not found
{
  "code": "not_found",
  "message": "ticket_id does not exist"
}
```
</ResponseExample>

## 提示

- 至少包含一个成功响应和一个错误响应。
- 使用真实的标识符和时间戳，让示例更贴近实际。
- 保持负载简洁，方便读者快速浏览。

## 相关页面

<Columns cols={2}>
  <Card title="API Playground" icon="flask-vial" href="/cn/api-reference/playground">
    在端点页面启用交互式 API 测试
  </Card>
  <Card title="OpenAPI Example" icon="plug" href="/cn/api-reference/openapi-example">
    查看自动生成的端点页面
  </Card>
</Columns>

<Columns cols={2}>
  <Card title="Examples Component" icon="code" href="/cn/components/examples">
    了解组件属性和格式设置规则
  </Card>
  <Card title="Fields Component" icon="list-check" href="/cn/components/fields">
    记录请求和响应架构
  </Card>
</Columns>

---

📦 **OpenAPI specs:** Every OpenAPI specification referenced by this documentation is available as a single download — https://jamdesk-docs.jamdesk.app/api-specs.zip