> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiIwYTMyYjJjMC04OWM0LTRjMDktOTgwZi04NzJiZjZkMzA4NGUiLCJleHAiOjE3NzgyNjQyNTEsImlhdCI6MTc3ODI2Mzk1MX0.LNPk_tnPiQFGyoSkjd7_UX8mFagFaHWb5AKw-qz-OOU
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 端点请求代码片段

> 了解如何在 Fern 中使用 EndpointRequestSnippet 组件在文档中引用 API 端点请求和代码示例。

使用 `<EndpointRequestSnippet>` 组件从您的 API 参考中引用端点请求。

## 用法

<div>
  <EndpointRequestSnippet endpoint="POST /chat/{domain}" />
</div>

```jsx Markdown
<EndpointRequestSnippet endpoint="POST /chat/{domain}" />
```

## 引用特定示例

<Steps>
  ### 在规范中设置示例名称

  <AccordionGroup>
    <Accordion title="OpenAPI">
      ```yaml openapi.yml {12}
      paths:
        /pet:
          put:
            summary: Update an existing pet 
            operationId: pets_update
            requestBody: 
              content:
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
                  examples:
                    ExampleWithMarkley:
                      value: 
                        name: Markley
                        id: 44
      ```
    </Accordion>

    <Accordion title="Fern Definition">
      ```yaml pets.yml {11}
      service:
        auth: true
        base-path: ""
        endpoints:
          update:
            docs: Update an existing pet 
            method: PUT
            path: /pet
            request: Pet
            examples:
              - name: ExampleWithMarkley
                request:
                  name: Markley
                  id: 44
      ```
    </Accordion>
  </AccordionGroup>

  ### 直接引用示例

  ```jsx Markdown {3}
    <EndpointRequestSnippet 
      endpoint="PUT /pet" 
      example="ExampleWithMarkley"
    />
  ```

  <Note title="引用示例">
    如果示例包含 `summary` 或 `docs` 字段，请使用该字段作为 `example` 属性。如果没有设置 summary，则使用示例名称。
  </Note>
</Steps>

## 变体

### 过滤语言

使用 `languages` 属性来过滤下拉菜单中出现的语言并控制它们的顺序。

<div>
  <div>
    <EndpointRequestSnippet endpoint="POST /chat/{domain}" languages={["curl", "python", "typescript"]} />
  </div>
</div>

```jsx Markdown
<EndpointRequestSnippet 
  endpoint="POST /chat/{domain}" 
  languages={["curl", "python", "typescript"]}
/>
```

### 显示载荷

`payload` 选项显示 POST/PUT/PATCH 请求的原始 JSON 请求体，或 GET 请求的查询参数。

<div>
  <div>
    <EndpointRequestSnippet endpoint="POST /chat/{domain}" languages={["curl", "python", "payload"]} />
  </div>
</div>

```jsx Markdown
<EndpointRequestSnippet 
  endpoint="POST /chat/{domain}" 
  languages={["curl", "python", "payload"]}
/>
```

### 隐藏试用按钮

`EndpointRequestSnippet` 组件默认包含试用按钮。使用 `hideTryItButton` 属性来隐藏它。

<div>
  <div>
    <EndpointRequestSnippet endpoint="POST /chat/{domain}" hideTryItButton={true} />
  </div>
</div>

```jsx Markdown
<EndpointRequestSnippet 
  endpoint="POST /chat/{domain}" 
  hideTryItButton={true}
/>
```

## 属性

<ParamField path="endpoint" type="string" required={true}>
  要显示的端点，格式为 `METHOD /path`（例如，`POST /chat/{domain}`）。如果您的 API 使用[命名空间](/learn/api-definitions/overview/project-structure#combined-sdks-from-multiple-apis)，请在前面加上命名空间和 `::`（例如，`payments::POST /chat/{domain}`）。
</ParamField>

<ParamField path="example" type="string" required={false}>
  要显示的特定示例的名称。如果示例包含 `summary` 或 `docs` 字段，请使用该值。
</ParamField>

<ParamField path="highlight" type="number | number[]" required={false}>
  代码片段中要高亮的行号。接受单个数字、数字数组或范围（例如，`{[1-3, 5]}`）。
</ParamField>

<ParamField path="languages" type="string[]" required={false}>
  指定在下拉菜单中显示哪些语言以及显示顺序。支持的值包括 `curl`、`python`、`typescript`、`javascript`、`go`、`ruby`、`java`、`kotlin`、`csharp`、`php`、`swift`、`rust` 和 `payload`。未指定时，显示所有可用语言。
</ParamField>

<ParamField path="hideTryItButton" type="boolean" required={false} default={false}>
  设置为 `true` 时，隐藏片段中的试用按钮。
</ParamField>