All Projects → lmerotta → phpokeapi

lmerotta / phpokeapi

Licence: other
A PHP7.1 Wrapper for PokéAPI, with cache and lazy-loading

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to phpokeapi

nextjs-ssr-isr-cdk-aws
🦄 ‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎Next.js webapp using Server Side Rendering (SSR) and Incremental Static Regeneration (ISR) deployed with Serverless Nextjs CDK construct on AWS using CloudFront and Lambda@Edge
Stars: ✭ 78 (+160%)
Mutual labels:  pokeapi, pokemon-api
pokenode-ts
A lightweight Node.js wrapper for the PokéAPI with built-in types.
Stars: ✭ 102 (+240%)
Mutual labels:  pokeapi, pokemon-api
Pokeapi
The Pokémon API
Stars: ✭ 2,695 (+8883.33%)
Mutual labels:  pokeapi
pokeapi.co
The PokéAPI documentation website
Stars: ✭ 66 (+120%)
Mutual labels:  pokeapi
dex-next
Pokedex App using NextJS and TailwindCSS
Stars: ✭ 28 (-6.67%)
Mutual labels:  pokeapi
pokedex
A simple Pokémon catalogue, built with React, Material-UI and PokéAPI.
Stars: ✭ 115 (+283.33%)
Mutual labels:  pokeapi
api-data
Static JSON data from the API, plus a JSON Schema
Stars: ✭ 88 (+193.33%)
Mutual labels:  pokeapi
graphql-pokeapi
🔴 The Unofficial GraphQL for PokeAPI
Stars: ✭ 137 (+356.67%)
Mutual labels:  pokeapi

PHPokéAPI

A PHP7.1+ wrapper for PokéAPI. This package offers the possibility to query the majority of the PokéAPI endpoints (see exceptions below). It supports caching of responses and lazy-loading relations.

Installation

composer require lmerotta/phpokeapi

Basic Usage

UsePokeAPI\Client to query the endpoints directly through the named methods.

<?php

use PokeAPI\Client;

$client = new Client();

// Returns a PokeAPI\Pokemon\Species instance
$species = $client->species('bulbasaur'); // or $client->species(1);

You can then traverse the returned object. All its relations will be proxies, and won't make any new requests to the API except if you explicitly call one of their getters

<?php

// ...

$species->getName(); // 'bulbasaur'
$growthRate = $species->getGrowthRate(); // A proxy of PokeAPI\Pokemon\GrowthRate 

$growthRate->getName(); // Here the real API call to the GrowthRate endpoint is made 

All the requests made are cached, so you won't have to query twice for the same dataset.

PokeAPI\Client

The PokeAPI\Client takes 3 optional parameters:

  • $url, a string pointing to the base URL of the PokéAPI. Defaults to pokeapi.co
  • $cache, A Psr\SimpleCache\CacheInterface. Defaults to a Symfony\Component\Cache\Simple\FilesystemCache instance
  • $serializer, A JMS\Serializer\SerializerInterface implementation.

Contributing

Feel free to open pull requests or submit issues!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].