> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJhMWEyMGUzYi1mYjYzLTRiNjEtODAwNy1kNzhkYjc3NmI3NTAiLCJleHAiOjE3NzgzODk5ODksImlhdCI6MTc3ODM4OTY4OX0.1_-HApsYtutiUFGnxZMNb0Q7_I3NYAIKUc3lB9mNEis
>
> 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 中自定义 SDK 方法名称来创建直观、用户友好的代码。配置组名称和方法结构以实现更好的 API 客户端设计。

您可以精细调整 SDK 方法和组名称，创建直观、用户友好的代码，使其符合您 API 的用途。例如，您可以将 `client.postUsers` 配置为更直观的 `client.users.create()`。

## 生成的 SDK 行为

Fern 使用您配置的组和方法名称生成 SDK 方法。大小写会自动适应每种语言（Python 中为 `snake_case`，TypeScript 中为 `camelCase`，Go 中为 `PascalCase` 等），因此您只需定义一次端点结构，就能在所有生成的 SDK 中获得正确格式的方法。

<CodeBlocks>
  <CodeBlock title="TypeScript">
    ```ts
    const response = await client.users.create();
    ```
  </CodeBlock>

  <CodeBlock title="Python">
    ```python
    response = client.users.create()
    # or async
    response = await async_client.users.create()
    ```
  </CodeBlock>

  <CodeBlock title="Java">
    ```java
    const response = client.users().create();
    ```
  </CodeBlock>

  <CodeBlock title="Go">
    ```go
    const response = client.Users.Create();
    ```
  </CodeBlock>
</CodeBlocks>

## 设置方法名称

在您的 API 定义中配置端点如何映射到 SDK 方法和组名称：

<Tabs>
  <Tab title="OpenAPI">
    ```yaml title="openapi.yaml" {4-5}
    paths:
      /users:
        post:
          x-fern-sdk-group-name: users
          x-fern-sdk-method-name: create
    ```
  </Tab>

  <Tab title="Fern Definition">
    ```yaml title="users.yml" {4, 6}
    services:
      http:
        UsersService: 
          base-path: /users # 定义方法的组/命名空间
          endpoints:
            create: # 定义组内的具体方法名称
              method: POST
              path: ""
    ```
  </Tab>
</Tabs>

有关完整配置详细信息，请参阅您的 API 定义格式的文档：

<CardGroup cols={2}>
  <Card title="OpenAPI" href="/learn/api-definitions/openapi/extensions/method-names">
    配置 `x-fern-sdk-group-name` 和 `x-fern-sdk-method-name` 扩展。
  </Card>

  <Card title="Fern Definition" href="/learn/api-definitions/ferndef/endpoints/overview">
    从服务 `base-path` 和端点名称映射方法名称。
  </Card>
</CardGroup>