2017 © Pedro Peláez
 

library consume

Retrieving data from a REST api without HTTP request.

image

teepluss/consume

Retrieving data from a REST api without HTTP request.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Consume Laravel REST api without HTTP request.

Consume your own API from the same application without request via HTTP protocol, (*1)

Installation

To get the latest version of Consume simply require it in your composer.json file., (*2)

"teepluss/consume": "^1.0.0"

You'll then need to run composer install to download it and have the autoloader updated., (*3)

Once Consume is installed you need to register the service provider with the application. Open up config/app.php and find the providers key., (*4)

'providers' => [

    Teepluss\Consume\ConsumeServiceProvider::class,

]

Consume also ships with a facade which provides the static syntax for creating collections. You can register the facade in the aliases key of your config/app.php file., (*5)

'aliases' => [

    'Consume' => Teepluss\Consume\Facades\Consume::class,

]

Usage

$accessToken = "[YOUR_ACCESS_TOKEN]";

// File uploading.
$userfile = request()->file('userfile');

// POST parameters.
$parameters = [
    'name'     => 'Teepluss',
    'userfile' => $userfile
];

try {
    $request = Consume::asJson()
                      ->withAccessToken($accessToken)
                      ->request('POST', '/api/user', $parameters)
                      ->send();

    $response = $request->getContent();
} catch (\Teepluss\Consume\Exception\ErrorException $e) {
    // This may return laravel validation error.
    $response = $e->getContent();
} catch (\Teepluss\Consume\Exception\NotFoundException $e) {
    $response = 'Not Found Exception';
}

Problem

If you are sending file upload to the REST api you need to get file directly., (*6)

// Not work
request()->file('userfile');

// work
request()->files->get('userfile');

Support or Contact

If you have any problems, Contact teepluss@gmail.com, (*7)

Support via PayPal, (*8)

The Versions

09/12 2016

dev-master

9999999-dev

Retrieving data from a REST api without HTTP request.

  Sources   Download

MIT

The Requires

 

laravel restful consume

09/12 2016

1.0.0

1.0.0.0

Retrieving data from a REST api without HTTP request.

  Sources   Download

MIT

The Requires

 

laravel restful consume