> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shipthing.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加新端点

> 如何在API中添加新端点。

所有API端点及其解析器都定义在`apps/api/`包中。在这里，您会找到一个包含API不同功能模块的routes文件夹。每个模块都有自己的文件夹，并导出其所有解析器。

## 创建新模块

要创建一个新模块，只需在`apps/api/app/server/api/routes`目录中创建一个新文件夹。例如，如果您想创建一个名为`hello`的新模块，您需要在`apps/api/app/server/api/routes`目录中创建一个名为`hello`的文件夹。

```ts apps/api/app/server/api/routes/hello/index.ts theme={"system"}
// apps/api/app/routes/auth.ts
import { Hono } from 'hono';

const app = new Hono();

const hello = app.basePath('/hello').get('/', (c) => {
  const { name } = c.req.query();
  return c.json({ message: `Hello ${name || 'World'}!` });
});

// export type AppType = typeof hello;
// export const GET = handle(app);
// export const POST = handle(app);
export default hello;
```

## 注册路由器

我们在`apps/api/app/server/api/index.ts`文件中创建一个单独的Hono路由，并将所有子路由器聚合到一个主路由器中。要使模块及其端点在API中可用，您需要在index.ts文件中为此模块注册一个路由器：

```ts apps/api/app/server/api/index.ts theme={"system"}
import hello from './routes/hello';


const routes = app.route('/', books);
```

就是这样！您刚刚创建了一个新的API端点 - 现在可以在`/api/hello`访问它了 🎉
