GithubHelp home page GithubHelp logo

jonathanmoreau / lswapicallerbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leaseweb/lswapicallerbundle

0.0 2.0 0.0 231 KB

Symfony2 bundle that adds cURL API call functionality with full Web Debug Toolbar integration.

License: MIT License

lswapicallerbundle's Introduction

LswApiCallerBundle

screenshot

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.

Read the LeaseWebLabs blog about LswApiCallerBundle

Requirements

  • PHP 5.3 with curl support
  • Symfony 2.1 (works under Symfony 2.0 as well)

Installation

Installation is broken down in the following steps:

  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:

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

Now tell composer to download the bundle by running the command:

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

Composer will install the bundle to your project's vendor/leaseweb directory.

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

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

Step 3: Make sure the cURL module in PHP is enabled

On a Debian based distribution (like Ubuntu) the package is called "php5-curl" and can be installed using the following commands:

$ sudo apt-get install php5-curl
$ sudo service apache2 restart

On a RedHat based distribution (like CentOS) the package is called "php-curl" and can be installed using the following commands:

$ sudo yum install php-curl
$ sudo service httpd restart

To check this create and run a PHP file with the following contents:

<?php phpinfo() ?>

It should display that the option "cURL support" is set to "enabled".

This package should work on a Windows installation as well provided the CURL support is enabled in PHP.

Usage

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

  • HttpGetJson
  • HttpPostJson
  • HttpPutJson
  • HttpDeleteJson
  • HttpGetHtml

Example of usage with the "HttpGetJson" call type:

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));
        ...
    }
}

Configuration

By default it uses these cURL options:

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.

License

This bundle is under the MIT license.

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.

lswapicallerbundle's People

Contributors

minras avatar tnajanssen avatar spoelwijk avatar zakharovvi avatar

Watchers

Jonathan Moreau avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.