PHPackages                             chaplean/rest-client-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. chaplean/rest-client-bundle

ActiveSymfony-bundle[API Development](/categories/api)

chaplean/rest-client-bundle
===========================

Create a Restful API Client quickly

v4.0.1(7y ago)08.0k2MITPHPPHP &gt;=7.0.8

Since Sep 12Pushed 6y agoCompare

[ Source](https://github.com/chaplean/rest-client-bundle)[ Packagist](https://packagist.org/packages/chaplean/rest-client-bundle)[ RSS](/packages/chaplean-rest-client-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (14)Versions (15)Used By (2)

Chaplean Rest-Client-Bundle
===========================

[](#chaplean-rest-client-bundle)

[![Codeship Status for chaplean/rest-client-bundle](https://camo.githubusercontent.com/0c8d20b59a2dbbe89a7d54ad09d11dc8d9c7e54dc227189097062b44a9bdd6af/68747470733a2f2f6170702e636f6465736869702e636f6d2f70726f6a656374732f33666535313736302d373663612d303133352d343430322d3136333962353831393964302f7374617475733f6272616e63683d6d6173746572)](https://app.codeship.com/projects/244562)[![Coverage Status](https://camo.githubusercontent.com/3a90066fc50d12669cfb5d1deb4b691e80651e85b4c2438aceb65e56145cc2be/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6269746275636b65742f636861706c65616e2f726573742d636c69656e742d62756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/bitbucket/chaplean/rest-client-bundle?branch=master)

Prerequisites
=============

[](#prerequisites)

This version of the bundle requires Symfony 2.8+.

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

[](#installation)

1. Composer
-----------

[](#1-composer)

```
composer require chaplean/rest-client-bundle
```

2. AppKernel.php
----------------

[](#2-appkernelphp)

Add

```
new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle(),
new Chaplean\Bundle\RestClientBundle\ChapleanRestClientBundle(),

// If you want to enable Database logging
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),

// If you want to enable Email logging
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle()
```

3. config.yml and parameters.yml
--------------------------------

[](#3-configyml-and-parametersyml)

First you will need to configure guzzlehttp that we use under the hood to perform the actual http requests. See the [bundle](https://github.com/8p/EightPointsGuzzleBundle) documentation or the [library](http://docs.guzzlephp.org/en/latest/request-options.html) documentation for full range of options. Example:

config.yml

```
eight_points_guzzle:
    logging: true
    clients:
        fake_api:
            # We inject guzzle configuration from parameters.yml but we could hardcode it here
            options: %fake_api.options%
```

You will probably also want to create some custom parameters.

parameters.yml

```
parameters:
    # Guzzle configuration
    fake_api.options:
        timeout: 10
        verify: false
        expect: false

    # Your custom configuration, here we just define the base url of our fake_api
    fake_api.url: 'http://fakeapi.com/'
```

As you inject guzzle in your Api class you can have different configuration per Api. See next section.

Next this bunde expose some configuration if you want to enable extra features. You can enable database and / or email logging of requests. To use the database or email loggers you will have to setup respectively [doctrine](https://symfony.com/doc/current/doctrine.html) or [swiftmailer](https://symfony.com/doc/current/email.html) in your project. The default configuraton is:

config.yml

```
chaplean_rest_client:
    enable_database_logging: false
    enable_email_logging: false
    email_logging:
        # Limit emails to the specified codes.
        # You can either use a code directly like 200, 404, …
        # or use XX to say all codes in the familly like 5XX to say all server errors.
        # 0 means that the request failed to run (either because of invalid parameters or a networking error)
        codes_listened: ['0', '1XX', '2XX', '3XX', '4XX', '5XX']
        address_from: ~
        address_to:   ~
```

You can override the default email content by overriding the translation keys or even the email body twig template. The translation keys are under `chaplean_rest_client.email.request_executed_notification` and the template is `Resources/views/Email/request_executed_notification.txt.twig`.

Usage
=====

[](#usage)

Creating Api class
------------------

[](#creating-api-class)

To use rest-client-bundle you have to create a class extending AbstractApi. You can create any number of classes extending AbstractApi and have all of them using different configurations via dependency injection.

```
