PHP code example of leaseweb / api-caller-bundle

1. Go to this page and download the library: Download leaseweb/api-caller-bundle 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/ */

    

leaseweb / api-caller-bundle example snippets

 bash
$ php composer.phar update leaseweb/api-caller-bundle
 php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Lsw\ApiCallerBundle\LswApiCallerBundle(),
    );
}
 php
 phpinfo() 
 php

use Symfony\Bundle\FrameworkBundle\Controller\Controller
use Lsw\ApiCallerBundle\Call\HttpGetJson;

class SomeController extends Controller
{
    public function someAction()
    {
        ...
        $output = $this->get('api_caller')->call(new HttpGetJson($url, $parameters));
        ...
    }
}

 php

use Symfony\Bundle\FrameworkBundle\Controller\Controller
use Lsw\ApiCallerBundle\Call\HttpPostJsonBody;

class SomeController extends Controller
{
    public function someAction()
    {
        ...
        $arrayToPost = array(
            'ip_address' => array(
                'name' => 'IpName',
                'hostname' => 'HostName',
                'ip' => '192.168.0.1',
                'throttling_template' => array(
                    'name' => 'Throttling Template'
                )
            )
        ); // this will be json_encode. If you don't want to json_encode, use HttpPostJson instead of HttpPostJsonBody
        $output = $this->get('api_caller')->call(new HttpPostJsonBody($url, $arrayToPost, true, $parameters)); // true to have an associative array as answer
        ...
    }
}