leaseweb/api-caller-bundle
Composer 安装命令:
composer require leaseweb/api-caller-bundle
包简介
cURL API call functionality with full Web Debug Toolbar integration
README 文档
README
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
Installation
Installation is broken down in the following steps:
- Download LswApiCallerBundle using composer
- Enable the Bundle
- 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
- HttpPostJsonBody (the body will be json_encode)
- 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)); ... } }
Example of usage with the "HttpPostJsonBody" call type:
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:
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.
leaseweb/api-caller-bundle 适用场景与选型建议
leaseweb/api-caller-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 418.71k 次下载、GitHub Stars 达 64, 最近一次更新时间为 2013 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「curl」 「Symfony2」 「api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 leaseweb/api-caller-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 leaseweb/api-caller-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 leaseweb/api-caller-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
Simple cURL wrapper
A PSR-7 compatible library for making CRUD API endpoints
A fluent PHP CURL wrapper
Symfony2 Barcode Generator Bundle with Twig function extension
Symfony bundle to connect AWS sns and sqs to create offline queue processing
统计信息
- 总下载量: 418.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 64
- 点击次数: 18
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-22