PHP code example of thomas-squall / php-easy-api

1. Go to this page and download the library: Download thomas-squall/php-easy-api 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/ */

    

thomas-squall / php-easy-api example snippets

 php
$mailchimp = new Mailchimp();
$mailchimp->dataCenter = '<YourDatacenter>';
$mailchimp->username = '<YourUsername>';
$mailchimp->apiKey = '<YourAPIKey>';

$resolver = new \PHPEasyAPI\Resolver();
$resolver->makeRequest($mailchimp, 'getLists');

print_r($mailchimp->getLists);
 php


/**
 * Class Listener.
 * [\PHPEasyAPI\Server("user")] // 'user' is the endpoint
 */
class Listener
{
    /**
     * @param \PHPEasyAPI\Request $request
     * @return string
     * [\PHPEasyAPI\Enrichment\Endpoint(method = "GET", url = ":userId/getList/:listId")]
     */
    public function getList($request)
    {
        $userId = $request["userId"];
        $listId = $request["listId"];
        $request->send200("List $listId of user $userId");
    }
}
 php
$resolver->setBaseUrl('http://localhost/MyTest'); // Assuming this is your local test url.
$resolver->bindListener(new Listener()); // 'user' is the endpoint.
 php
$resolver->resolve(); // Example call: GET http://localhost/MyTest/user/10/getList/15