REST API参考
🌐 REST API reference
Page summary:Strapi 的 REST API 会自动为内容类型生成端点,使用 GET、POST、PUT 和 DELETE 方法来获取、创建、更新和删除文档,并支持过滤、排序、字段选择和关联填充。
🌐 Strapi's REST API automatically generates endpoints for content-types to fetch, create, update, and delete documents using GET, POST, PUT, and DELETE methods, with support for filtering, sorting, field selection, and relation population.
REST API 允许通过 API 端点访问 内容类型。Strapi 在创建内容类型时会自动创建 API 端点。在查询 API 端点时可以使用 API 参数 来优化结果。
🌐 The REST API allows accessing the content-types through API endpoints. Strapi automatically creates API endpoints when a content-type is created. API parameters can be used when querying API endpoints to refine the results.
本节文档是针对内容类型的 REST API 参考。我们还提供了针对特定用例的指南。
🌐 This section of the documentation is for the REST API reference for content-types. We also have guides available for specific use cases.
所有内容类型默认都是私有的,需要将其设为公开,或者查询需要使用适当权限进行认证。有关更多详细信息,请参阅快速入门指南、用户与权限功能用户指南,以及API 令牌配置文档。
🌐 All content types are private by default and need to be either made public or queries need to be authenticated with the proper permissions. See the Quick Start Guide, the user guide for the Users & Permissions feature, and API tokens configuration documentation for more details.
默认情况下,REST API 响应仅包含顶层字段,不会填充任何关系、媒体字段、组件或动态区域。使用 populate 参数 来填充特定字段。确保为要填充的关系的字段授予查找权限。
🌐 By default, the REST API responses only include top-level fields and does not populate any relations, media fields, components, or dynamic zones. Use the populate parameter to populate specific fields. Ensure that the find permission is given to the field(s) for the relation(s) you populate.
Strapi 客户端 库简化了与你的 Strapi 后端的交互,提供了一种获取、创建、更新和删除内容的方式。
🌐 The Strapi Client library simplifies interactions with your Strapi back end, providing a way to fetch, create, update, and delete content.
端点
🌐 Endpoints
对于每个 Content-Type,会自动生成以下端点:
🌐 For each Content-Type, the following endpoints are automatically generated:
复数 API ID 与单数 API ID:
在下表中:
🌐 In the following tables:
:singularApiId指内容类型中“API ID(单数)”字段的值,- 而
:pluralApiId指的是内容类型的“API ID(复数)”字段的值。
这些值是在内容类型构建器中创建内容类型时定义的,并且可以在管理面板编辑内容类型时找到(参见 用户指南)。例如,对于“文章”内容类型,默认情况下:
🌐 These values are defined when creating a content-type in the Content-Type Builder, and can be found while editing a content-type in the admin panel (see User Guide). For instance, by default, for an "Article" content-type:
:singularApiId将是article:pluralApiId将是articles


- Collection type
- Single type
上传包(为媒体库功能提供支持)有一个特定的 API,可通过其/api/upload端点访问。
🌐 The Upload package (which powers the Media Library feature) has a specific API accessible through its /api/upload endpoints.
组件 没有 API 端点。
请求和响应
🌐 Requests and responses
Strapi 5 的内容 API 与 Strapi v4 有 2 个主要区别:
🌐 Strapi 5's Content API includes 2 major differences with Strapi v4:
- 响应格式已被扁平化,这意味着属性不再嵌套在
data.attributes对象中,而是可以直接在data对象的第一层访问(例如,内容 类型的“title”属性可以使用data.title访问)。 - Strapi 5 现在使用 文档 ,并且文档通过它们的
documentId访问(详情请参见 重大更改条目)
请求以对象形式返回响应,通常包含以下键:
🌐 Requests return a response as an object which usually includes the following keys:
data:响应数据本身,可以是:- 单个文档,作为具有以下键的对象:
id(整数)documentId(字符串),这是在查询特定文档时使用的唯一标识符,- 属性(每个属性的类型取决于该属性,详细信息请参阅 models attributes 文档)
meta(对象)
- 文档列表,作为对象数组
- 单个文档,作为具有以下键的对象: