This package is a POO-oriented AND procedural API PHP wrapper. With MagicApiPhpWrapper, you can easily obtain data from online API. The package includes a built-in caching system.
Require this package with composer:
composer require iarcadia/magic-api-php-wrapper
// "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');
Don't forget to include
files or to use
classes. (e.g. use iArcadia\MagicApiPhpWrapper\MAPW
)
// 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');
Don't forget to include
files.
See CHANGELOGS.md