2017 © Pedro Peláez
 

symfony-bundle api-caller-bundle

cURL API call functionality with full Web Debug Toolbar integration

image

leaseweb/api-caller-bundle

cURL API call functionality with full Web Debug Toolbar integration

  • Thursday, February 8, 2018
  • by LeaseWeb
  • Repository
  • 11 Watchers
  • 63 Stars
  • 202,103 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 32 Forks
  • 5 Open issues
  • 25 Versions
  • 4 % Grown

The README.md

LswApiCallerBundle

screenshot, (*1)

The LswApiCallerBundle adds a CURL API caller to your Symfony2 application. It is easy to use from the code and is aimed to have full debugging capabilities., (*2)

Read the LeaseWebLabs blog about LswApiCallerBundle, (*3)

Requirements

  • PHP 5.3 with curl support
  • Symfony >= 2.1

Installation

Installation is broken down in the following steps:, (*4)

  1. Download LswApiCallerBundle using composer
  2. Enable the Bundle
  3. Make sure the cURL module in PHP is enabled

Step 1: Download LswApiCallerBundle using composer

Add LswApiCallerBundle in your composer.json:, (*5)

{
    "require": {
        "leaseweb/api-caller-bundle": "*",
        ...
    }
}

Now tell composer to download the bundle by running the command:, (*6)

``` bash $ php composer.phar update leaseweb/api-caller-bundle, (*7)


Composer will install the bundle to your project's `vendor/leaseweb` directory. ### Step 2: Enable the bundle Enable the bundle in the kernel: ``` php

It should display that the option "cURL support" is set to "enabled"., (*8)

This package should work on a Windows installation as well provided the CURL support is enabled in PHP., (*9)

Usage

You can use the caller by getting the service "api_caller" and using the "call" function with one of the available call types:, (*10)

  • HttpGetJson
  • HttpPostJson
  • HttpPostJsonBody (the body will be json_encode)
  • HttpPutJson
  • HttpDeleteJson
  • HttpGetHtml

Example of usage with the "HttpGetJson" call type:, (*11)

``` php, (*12)

use Symfony\Bundle\FrameworkBundle\Controller\Controller use Lsw\ApiCallerBundle\Call\HttpGetJson;, (*13)

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


Example of usage with the "HttpPostJsonBody" call type: ``` 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 ... } }

Configuration

By default it uses these cURL options: yaml parameters: api_caller.options: timeout: 10 # maximum transport + execution duration of the call in sec. ssl_verifypeer: false # to stop cURL from verifying the peer's certificate. useragent: "LeaseWeb API Caller" # contents of the "User-Agent: " header. followlocation: true # to follow any "Location: " header that the server sends. sslversion: 3 # set to 3 to avoid any bugs that relate to automatic version selection. fresh_connect: false # set to true to force full reconnect every call., (*15)

License

This bundle is under the MIT license., (*16)

The "wall-socket" icon in the web debug toolbar is part of the Picas icon set (official website: http://www.picasicons.com). The icon is licensed and may only be used to identifying the LswApiCallerBundle in the Symfony2 web debug toolbar. All ownership and copyright of this icon remain the property of Rok Benedik., (*17)

The Versions

06/02 2018

dev-bugfix/fix-php-53-support

dev-bugfix/fix-php-53-support http://www.leaseweblabs.com

cURL API call functionality with full Web Debug Toolbar integration

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl symfony2