The Marvel Comics API allows developers everywhere to access information about Marvel's vast library of comics—from what's coming up, to 70 years ago. This Marvel API bundle helps you explore the Marvel universe with great ease.
- PHP 7.1.0
- Marvel API key
- Love for Marvel
Open a command console, enter your project directory and execute:
$ composer require ikoene/marvel-api-bundleOpen a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require ikoene/marvel-api-bundleThis command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Ikoene\MarvelApiBundle\IkoeneMarvelApiBundle(),
);
// ...
}
// ...
}# You will need a public and private api key from https://developers.marvel.com.
# Set the keys as environment variables in the .env file.
ikoene_marvel_api:
public_api_key: "%env(MARVEL_PUBLIC_API_KEY)%"
private_api_key: "%env(MARVEL_PRIVATE_API_KEY)%"<?php
$client = $this->get('ikoene_marvel_api_client');
$response = $client->getCharacter(1009610);
var_dump($response);
You can call every endpoint with an explicitly defined method. So if you, for example, want a list of comics containing a specific character, you can call getComicsForCharacter().
$response = $client->getComicsForCharacter(1009610);
It's also possible to add optional filters to the calls. Let's get all comics for 'Spider-Man' which title starts with 'Age of Ultron' and order the results by 'title'.
$comicFilter = new Ikoene\MarvelApiBundle\Entity\ComicFilter();
$comicFilter->setTitleStartsWith('Age of Ultron');
$comicFilter->setOrderBy('title');
$response = $client->getComicsForCharacter(1009610, $comicFilter);
Pretty easy, right?
