Strapi API 访问你的内容
🌐 Strapi APIs to access your content
Page summary:Strapi 的内容 API 通过 REST 和 GraphQL API 为前端应用提供对内容的访问,同时为后端和插件开发提供更底层的文档服务和查询引擎 API。
🌐 Strapi's Content API provides access to your content through REST and GraphQL APIs for front-end applications, plus lower-level Document Service and Query Engine APIs for backend and plugin development.
一旦你创建并配置了一个 Strapi 项目,使用 内容类型构建器 创建了内容结构,并通过 内容管理器 开始添加数据,你可能希望访问你的内容。
🌐 Once you've created and configured a Strapi project, created a content structure with the Content-Type Builder and started adding data through the Content Manager, you likely would like to access your content.
从前端应用,你的内容可以通过 Strapi 的 Content API 访问,该 API 公开:
🌐 From a front-end application, your content can be accessed through Strapi's Content API, which is exposed:
- 默认通过 REST API
- 如果你安装了 Strapi 内置的 GraphQL 插件,也可以通过 GraphQL API 访问。
你也可以使用 Strapi Client 库与 REST API 进行交互。
🌐 You can also use the Strapi Client library to interact with the REST API.
REST 和 GraphQL API 代表了面向外部应用暴露的内容 API 的顶层。Strapi 还提供了两个较低层次的 API:
🌐 REST and GraphQL APIs represent the top-level layers of the Content API exposed to external applications. Strapi also provides 2 lower-level APIs:
- 文档服务 API,可通过
strapi.documents访问,是在 后端服务器 内或通过 插件 与你的应用数据库交互的推荐 API。文档服务是处理 文档 以及 Strapi 的复杂内容结构(如组件和动态区域)的层。 - 查询引擎 API 可通过
db.query(即strapi.db.query)访问,它在更底层与数据库层交互,并用于在后台执行数据库查询。它提供对数据库层的不受限制的内部访问,但无法识别 Strapi 5 可以处理的任何高级功能,例如草稿与发布、国际化、内容历史等。
⚠️ 在大多数(如果不是所有)使用场景中,你应该使用文档服务 API。

本文档部分包括有关以下 Strapi API 的参考信息以及一些与第三方技术的集成指南:
🌐 This documentation section includes reference information about the following Strapi APIs and some integration guides with 3rd party technologies:
REST API
通过 REST 从前端应用查询内容 API。
GraphQL API
通过 GraphQL 从前端应用查询内容 API。
Strapi 客户端
通过 Strapi 客户端库与 REST API 进行交互。
文档服务 API
通过后端服务器或插件查询你的数据。
OpenAPI 规范
为你的 Strapi 应用生成 OpenAPI 规范。
如果你想了解如何将 Strapi 与其他平台(如 Next.js、 Astro、 Angular等)集成,请参考 Strapi 的 integrations pages。