PHP code example of iarcadia / php-magic-pokeapi

1. Go to this page and download the library: Download iarcadia/php-magic-pokeapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iarcadia / php-magic-pokeapi example snippets


$api = new PokeAPI();

$api->resource('pokemon');
// or (and the recommended one)
$api->resource(PokeAPI::RESOURCE_POKEMON);

$api->limit(20);

$api->offset(5);
// or
$api->skip(5);

$data = $api->get();

// by name
$item = $api->find('arcanine');
// or by id
$item = $api->find(25);

// endpoint
$api->raw('/ability/');
// with parameters
$api->raw('/pokemon-species/?limit=30&offset=60');
// resource details
$api->raw('/pokemon/bulbasaur/');
// with full URL
$api->raw('https://www.pokeapi.co/api/v2/item/203');

// array way
$api->raw(['/ability/', 'https://www.pokeapi.co/api/v2/item/203']);
// many args way
$api->raw('/ability/', 'https://www.pokeapi.co/api/v2/item/203');

$api->cacheForcing(true);

// for endpoint
$api->limit(20)->offset(60)->resource(PokeAPI::RESOURCE_ITEM)->get();
// for resource details
$api->resource(PokeAPI::RESOURCE_ITEM)->find('potion');

$api = new PokeApi(
[
    'limit' => 20,
    'offset' => 0, // works with "skip" too
    'resource' => PokeAPI::RESOURCE_CONTEST_EFFECT
]);

// Charizard in french will be translated to:
// $api->resource(PokeAPI::RESOURCE_POKEMON)->find('charizard');
$api->resource(PokeAPI::RESOURCE_POKEMON)->find('dracaufeu');

// Nidoqueen in korean will be translated to:
// $api->resource(PokeAPI::RESOURCE_POKEMON)->find('nidoqueen');
$api->resource(PokeAPI::RESOURCE_POKEMON)->find('니드퀸');

composer 
cache.php
request.php
lang.php
src/PokeAPI.php
limit()
config/lang.php