REST API 文档

区块目录项目

💡 云策文档标注

概述

本文档定义了区块目录项目的 JSON 模式,并提供了查询区块目录项目的 REST API 端点。它详细说明了区块目录项目记录的字段结构,以及如何通过 GET 请求检索和过滤区块集合。

关键要点

  • 区块目录项目模式包含多个字段,如 name、title、description、id、rating、rating_count、active_installs、author_block_rating、author_block_count、author、icon、last_updated 和 humanized_updated,每个字段都有 JSON 数据类型和上下文(view)。
  • 使用 GET /wp/v2/block-directory/search 端点可以检索区块目录项目集合,支持查询参数如 context、page、per_page 和 term 来控制响应。
  • 除非使用 _filter 查询参数或字段仅出现在特定上下文中,否则响应将包含所有模式字段。

代码示例

$ curl https://example.com/wp-json/wp/v2/block-directory/search

📄 原文内容

Schema

The schema defines all the fields that exist within a block directory item record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.

name The block name, in namespace/block-name format.

JSON data type: string

Context: view

title The block title, in human readable format.

JSON data type: string

Context: view

description A short description of the block, in human readable format.

JSON data type: string

Context: view

id The block slug.

JSON data type: string

Context: view

rating The star rating of the block.

JSON data type: number

Context: view

rating_count The number of ratings.

JSON data type: integer

Context: view

active_installs The number sites that have activated this block.

JSON data type: integer

Context: view

author_block_rating The average rating of blocks published by the same author.

JSON data type: number

Context: view

author_block_count The number of blocks published by the same author.

JSON data type: integer

Context: view

author The WordPress.org username of the block author.

JSON data type: string

Context: view

icon The block icon.

JSON data type: string,
Format: uri

Context: view

last_updated The date when the block was last updated.

JSON data type: string,
Format: datetime (details)

Context: view

humanized_updated The date when the block was last updated, in fuzzy human readable format.

JSON data type: string

Context: view

List Block Directory Items

Query this endpoint to retrieve a collection of block directory items. The response you receive can be controlled and filtered using the URL query parameters below.

Definition

GET /wp/v2/block-directory/search

Example Request

$ curl https://example.com/wp-json/wp/v2/block-directory/search

Arguments

context Scope under which the request is made; determines fields present in response.

Default: view

One of: view

page Current page of the collection.

Default: 1

per_page Maximum number of items to be returned in result set.

Default: 10

term Limit result set to blocks matching the search term.

Required: 1