Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cosminseceleanu/restclientbundle

Symfony Rest Client Bundle
https://github.com/cosminseceleanu/restclientbundle

annotations guzzlehttp httpclient php restclient symfony

Last synced: about 1 month ago
JSON representation

Symfony Rest Client Bundle

Awesome Lists containing this project

README

        

# RestClientBundle

Symfony **Rest Client Bundle** using [GuzzleHttp](http://docs.guzzlephp.org/en/latest/index.html) and [Ocramius/ProxyManager](http://ocramius.github.io/ProxyManager/)

Installation
============

To install CosRestClientBundle with Composer execute the following command:

$ composer require "cos/rest-client-bundle": "dev-master"

Now, Composer will automatically download all required files, and install them
for you. All that is left to do is to update your ``AppKernel.php`` file, and
register the new bundle:

get('cos_rest_client.proxy_factory');
$proxy = $proxyFactory->create(Posts::class);

Call proxy methods defined in interface
-----

get(1); //request for client base uri + /posts/1
$proxy->getWithQuery(1)->getBody()->getContents(); //request for /posts?userId=1
$data = ['foo' => 'bar']
$proxy->form($data) //post request where $data is sent as application/x-www-form-urlencoded
$proxy->json($data) // send data as json

Response
-----
Every method call from a proxy return a [Psr\Http\Message\ResponseInterface](http://docs.guzzlephp.org/en/latest/quickstart.html#using-responses)

Full example
--------
https://github.com/cosminseceleanu/RestClientBundleSample

Events
=======

**RequestEvent**: dispatched before a request is executed

**ResponseEvent**: dispatched when response is received