组件演示

以 Markdown 格式查看

此页面包含用于测试和展示各种文档组件的演示内容。它在导航中隐藏,但可以从示例中链接到。

API 客户端示例

PlantClient

PlantClient 类是与植物商店 API 交互的主要入口点。它处理身份验证、请求管理,并提供对所有 API 端点的访问。

构造函数参数:

  • apiKey (string, 必需): 您的 API 身份验证密钥
  • baseUrl (string, 可选): 用于测试的自定义 API 基础 URL
  • timeout (number, 可选): 请求超时时间(毫秒)

使用示例:

1import { PlantClient } from "@plantstore/sdk";
2
3const client = new PlantClient({
4 apiKey: "your-api-key-here"
5});

PlantConfig

用于自定义植物商店 SDK 行为的配置对象。

属性:

  • retryAttempts (number): 失败请求的重试次数
  • cacheEnabled (boolean): 启用响应缓存
  • logLevel (string): 日志详细程度级别

createPlant

在数据库中创建新的植物条目。

参数:

  • name (string, 必需): 植物的常用名称
  • species (string, 必需): 科学物种名称
  • description (string, 可选): 植物描述
  • careLevel (string, 可选): 护理难度级别

返回值: 解析为已创建植物对象的 Promise

示例:

1const plant = await client.createPlant({
2 name: "Monstera",
3 species: "Monstera deliciosa",
4 careLevel: "easy"
5});

API 方法示例

create_plant

用于创建新植物条目的 Python 方法。

签名:

1def create_plant(
2 name: str,
3 species: str,
4 description: Optional[str] = None,
5 care_level: Optional[str] = None
6) -> Plant

fetchPlants

从 API 检索植物列表,支持可选过滤。

参数:

  • filters (object, 可选): 过滤条件
  • limit (number, 可选): 最大结果数量
  • offset (number, 可选): 分页偏移量

返回值: 解析为植物对象数组的 Promise

类型定义

PlantStore

PlantStore 类管理植物数据存储和检索操作。

构造函数参数:

  • apiKey (string, 必需): 您的 API 身份验证密钥
  • config (PlantConfig, 可选): 配置选项

PlantClient

PlantClient 类提供与 PlantStore 交互的客户端接口。

构造函数参数:

  • store (PlantStore, 必需): 要使用的 PlantStore 实例

PlantResponse

从植物相关 API 调用返回的响应对象。

属性:

  • plants (Array): 植物对象列表
  • total (number): 植物总数
  • hasMore (boolean): 是否有更多结果可用

Get 方法

用于访问植物商店资源的常用检索方法。

方法描述参数返回值
getPlant通过 ID 检索单个植物plant_id (string, 必需): 植物的唯一标识符植物对象
getGarden通过 ID 检索单个花园garden_id (string, 必需): 花园的唯一标识符花园对象