Skip to main content

Strapi API 访问你的内容

🌐 Strapi APIs to access your content

一旦你创建并配置了一个 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:

你也可以使用 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。
Content APIs diagramContent APIs diagram

本文档部分包括有关以下 Strapi API 的参考信息以及一些与第三方技术的集成指南:

🌐 This documentation section includes reference information about the following Strapi APIs and some integration guides with 3rd party technologies: