PHP code example of iarcadia / magic-api-php-wrapper

1. Go to this page and download the library: Download iarcadia/magic-api-php-wrapper 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 / magic-api-php-wrapper example snippets


// "MAPW" stands for "Magic API PHP Wrapper"... of course!

// First, create your MAPW object with your configuration.
$api = new MAPW(
[
    'api.base_url' => 'https://www.your-awesome-url.com/api/',
    'api.key' => 'YourAwesomeApiKeyIfNeeded',
    'cache.use' => false,
    // ...
]);

// Second, get your data!
// Here, data will be from "https://www.your-awesome-url.com/api/countries":
$data = $api->get('countries');
// Here, data will be from "https://www.your-awesome-url.com/api/countries?from=Asia":
$data = $api->get('countries', ['from' => 'Asia']);
// Here, data will be from "https://www.your-awesome-url.com/api/cities?from=Spain&from=Italia":
$data = $api->get('https://www.your-awesome-url.com/api/cities?from=Spain&from=Italia');

// First, initialize the MAPW object with your configuration.
// In background, it will create a global variable with the newly created object : $GLOBALS['MAPW_INSTANCE'] = new MAPW(...)
mapw_initialize(
[
    'api.base_url' => 'https://www.your-awesome-url.com/api/',
    'api.key' => 'YourAwesomeApiKeyIfNeeded',
    'cache.use' => false,
    // ...
])

// Second, get your data!
// Here, data will be from "https://www.your-awesome-url.com/api/countries":
$data = mapw_get('countries');
// Here, data will be from "https://www.your-awesome-url.com/api/countries?from=Asia":
$data = mapw_get('countries', ['from' => 'Asia']);
// Here, data will be from "https://www.your-awesome-url.com/api/cities?from=Spain&from=Italia":
$data = mapw_get('https://www.your-awesome-url.com/api/cities?from=Spain&from=Italia');

composer