💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
[TOC] ## API 路由 pages 模式 ``` pages/api/post/[pid].js ``` app 模式 ``` pages/api/post/[pid].js ``` 代码 ``` export default function handler(req, res) { const { pid } = req.query res.end(`Post: ${pid}`) } ``` ## 示例 ### 索引路由(Index routes)和动态 API 路由 一个通常的 RESTful 模式将设置以下路由: * `GET api/posts`\- 获取 post 列表,可能还有分页 * `GET api/posts/12345`\- 获取 id 为 12345 的 post 我们可以按照如下两种方式建模: * 方案 1: * `/api/posts.js` * `/api/posts/[postId].js` * 方案 2: * `/api/posts/index.js` * `/api/posts/[postId].js` ### 捕获所有 API 的路由