sammyjo20/pokeapi-sdk

Pokeapi 的非官方 PHP SDK

v2.0.0 2023-10-01 14:01 UTC

This package is auto-updated.

Last update: 2024-08-30 01:55:19 UTC


README

这是一个使用 Saloon v3 构建的 PHP SDK 示例。

可用的请求

  • Pokeapi\Requests\GetAllPokemon
  • Pokeapi\Requests\GetAllItems

安装

使用 Composer 安装此 SDK

composer require sammyjo20/pokeapi-sdk

用法

只需调用您想要发送的请求类的 send 方法。发送后,将返回一个 PokeapiResponse

<?php

use Pokeapi\Pokeapi;
use Pokeapi\Requests\GetAllPokemon;

$pokeapi = new Pokeapi();

$response = $pokeapi->send(new GetAllPokemon);

分页结果

您可以通过在 SDK 上使用 paginate 方法来检索分页请求的所有结果。

<?php

use Pokeapi\Pokeapi;
use Pokeapi\Requests\GetAllPokemon;

$pokeapi = new Pokeapi();

$paginator = $pokeapi->paginate(new GetAllPokemon);

foreach($paginator->items() as $item) {
    // Handle result
}