2017 © Pedro PelĂĄez
 

symfony-bundle simple-api-caller-bundle

A simple API caller for Symfony framework

image

rubenrubiob/simple-api-caller-bundle

A simple API caller for Symfony framework

  • Monday, June 5, 2017
  • by rubenrubiob
  • Repository
  • 2 Watchers
  • 1 Stars
  • 90 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 6 % Grown

The README.md

This is a simple bundle built on top of Httpful that performs GET or POST requests to an url, and parses the JSON response to a PHP array. It supports sending custom headers, as well as attached files using the Symfony FileUploaded class., (*1)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*2)

$ composer require rubenrubiob/simple-api-caller-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*3)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*4)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new rubenrubiob\SimpleApiCallerBundle\rubenrubiobSimpleApiCallerBundle(),
        );

        // ...
    }

    // ...
}

Usage

The caller is provided as a service, so you may use it wherever you want. Below there are examples of use within a controller., (*5)

GET requests

$url = 'http://your/complete/url';
$headers = array(
    'header-1-name'     => 'header-1-value',
    'header-2-name'     => 'header-2-value',
);

$response = $this->get('rrb.simple_api_caller')->get($url, $headers);

POST requests

use Symfony\Component\HttpFoundation\File\UploadedFile;

// ...

$url = 'http://your/complete/url';
$data = array(
    'field-1'       => 'field-1-value',
    'field-2'       => new UploadedFile('/path/to/file', 'file-name'),
    'field-3'       => array(
        'subfield-3.1'   => 'subvalue-3.1',
        'subfield-3.2'   => 'subvalue-3.2',
    ),
);
$headers = array(
    'header-1-name'     => 'header-1-value',
    'header-2-name'     => 'header-2-value',
);

$response = $this->get('rrb.simple_api_caller')->post($url, $data, $headers);

PUT requests

use Symfony\Component\HttpFoundation\File\UploadedFile;

// ...

$url = 'http://your/complete/url';
$data = array(
    'field-1'       => 'field-1-value',
    'field-2'       => new UploadedFile('/path/to/file', 'file-name'),
    'field-3'       => array(
        'subfield-3.1'   => 'subvalue-3.1',
        'subfield-3.2'   => 'subvalue-3.2',
    ),
);
$headers = array(
    'header-1-name'     => 'header-1-value',
    'header-2-name'     => 'header-2-value',
);

$response = $this->get('rrb.simple_api_caller')->put($url, $data, $headers);

PATCH requests

use Symfony\Component\HttpFoundation\File\UploadedFile;

// ...

$url = 'http://your/complete/url';
$data = array(
    'field-1'       => 'field-1-value',
    'field-2'       => new UploadedFile('/path/to/file', 'file-name'),
    'field-3'       => array(
        'subfield-3.1'   => 'subvalue-3.1',
        'subfield-3.2'   => 'subvalue-3.2',
    ),
);
$headers = array(
    'header-1-name'     => 'header-1-value',
    'header-2-name'     => 'header-2-value',
);

$response = $this->get('rrb.simple_api_caller')->patch($url, $data, $headers);

Expects

By default, the service expects a JSON response and parses it as an array. But it is possible to specify the MIME type to expect:, (*6)

$url = 'http://your/complete/url';
$headers = array(
    'header-1-name'     => 'header-1-value',
    'header-2-name'     => 'header-2-value',
);

$response = $this->get('rrb.simple_api_caller')->expects('html')->get($url, $headers);

The MIME types supported are the ones of Httpful, so check it for further information., (*7)

The Versions

05/06 2017

dev-master

9999999-dev

A simple API caller for Symfony framework

  Sources   Download

MIT

The Requires

 

by Rubén Rubio Barrera

api json bundle simple caller

05/06 2017

0.0.5

0.0.5.0

A simple API caller for Symfony framework

  Sources   Download

MIT

The Requires

 

by Rubén Rubio Barrera

api json bundle simple caller

25/02 2017

0.0.4

0.0.4.0

A simple API caller for Symfony framework

  Sources   Download

MIT

The Requires

 

by Rubén Rubio Barrera

api json bundle simple caller

14/06 2016

0.0.3

0.0.3.0

A simple API caller for Symfony framework

  Sources   Download

MIT

The Requires

 

by Rubén Rubio Barrera

api json bundle simple caller

15/05 2016

0.0.2

0.0.2.0

A simple API caller for Symfony framework

  Sources   Download

MIT

The Requires

 

by Rubén Rubio Barrera

api json bundle simple caller

06/03 2016

0.0.1

0.0.1.0

A simple API caller for Symfony framework

  Sources   Download

MIT

The Requires

 

by Rubén Rubio Barrera

api json bundle simple caller