D
D
dk-web2015-10-29 01:32:53
Laravel
dk-web, 2015-10-29 01:32:53

Is there an alternative to Guzzle for requests to external apis or how to properly include it in your package?

Actually the subject ...
I already have a sports interest ... a powerful framework, but for each iteration you still need to install a bunch of things that are often incompatible with each other ((
The task is banal to the point of impossibility - to send a get request to a third-party api and get a response.
It only turned out via Guzzle.But when installing it, another 20 megabytes of any slag was installed...
Update: If there is no alternative... then
how to connect this Guzzle only to your package
? you need to write require 'vendor/autoloader.php'; - where?? Maybe something else needs to be added to app/config.php? Now the structure is as follows

packages:
  dkweb
    mypackage
      src
         http
            Controllers
                RestClient.php
         MypackageServiceProvider.php
      vendor
         guzzlehttp
      config
      composer.json

<?php
namespace Dkweb\Mypackage\Http\Controllers;

use GuzzleHttp\Client;
class RestClient
{
protected function request($apiCall, $params = array())
    {
        $client = new Client([
            'base_uri' => $this->apiUrl.$apiCall
        ]);
        return $client->request('GET','?Id=48&appKey=60');
    }
}

FatalErrorException in RestClient.php line :
Class 'GuzzleHttp\Client' not found

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Elchev, 2015-10-29
@dk-web

I already have a sporting interest ... a powerful framework, but for each iteration you still need to install a bunch of things that are often incompatible with each other

You don’t need to connect anything, all these packages are installed at will, so as not to write your own bike every time, and it was because of the possibility of simply connecting packages that everyone fell in love with ruby, and then composer appeared in php.
Of course, Guzzle is a wrapper over the regular CURL, if you don’t want to use the convenient Guzzle, write requests for CURL by hand, if 20mb is so critical for you and you can’t use a convenient package, then this is your choice.
For which package? You are not writing an application in laravel, but a package for it?
But in any case, read about dependencies and how composer works.
Connection in laravel looks like this:
1) Add to require composer.json
2) composer update
3) you can use
In the class where you want to use Guzzle, connect namespaces, for example, use GuzzleHttp\Client and everything works, if it doesn’t work, then you made a mistake somewhere ( although it’s hard to make a mistake in two simple steps) and you need to look at your code.
If you are developing your package, then you actually need to watch how you do it. But in general, the situation is not much different. The main difference is that it needs to be added to the composer.json of the package, not the application

I
Ivan Brezhnev, 2015-10-30
@vanchelo

The simplest GET requests can be made through
If you need something more convenient and customizable, there is a good and intuitive nategood/httpful package

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question