Cphalcon: Functionality to call 3rd party services

Created on 15 Jan 2019  路  8Comments  路  Source: phalcon/cphalcon

Handler for Curl/Curl Multi/Stream

Currently there is no functionality to call 3rd party services using built in classes, Please provide handler for Curl/Curl Multi/Stream packaged with cphalcon

Most helpful comment

just use guzzle

All 8 comments

I think You have all possibilities to extend functionality

  1. extend Request as MyRequest
  2. use same or extend Factory/builder and use yours in Di setup

Something like that?

use MyApp\Request as MyRequest;
di->setShared('request', ... MyRequest ... )

where

class MyRequest extends Request
{
   public static function getProvider() { return new MyRequest () }
}

It is in the incubator.

https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Http/Client

I would suggest using something else however

just use guzzle

That is a good idea. However we cannot reinvent the wheel for everything. A Http library is a project on its own (see Guzzle as @JABirchall mentioned). We can offer a basic functionality by implementing this but the gain will be minimal, since for HTTP performance is only measured by how fast your network is.

I don;t quite understand what you mean by Currently there is no functionality to call 3rd party services using built in classes.

Where would you want to call something else from a Phalcon class? Can you offer an example?

I think he is asking to include http client library for curl or stream with cphalcon.
It would be great to have a functionality built into cphalcon.
Starting with basic features, it can be enriched later.
Incubator Http Client is a good starting point.

Example:
`
use Phalcon\Http\Client\Request;
use Phalcon\Http\Client\Request\Exception;
use Phalcon\Http\Client\Response;
use Phalcon\Http\Client\Response\Exception;

$request = new Request($options); // Request should use available provide like curl, stream, etc.
$response = $client->post($uri,$data,$options); // should return Response object
`

I think he is asking to include http client library for curl or stream with cphalcon.
It would be great to have a functionality built into cphalcon.
Starting with basic features, it can be enriched later.
Incubator Http Client is a good starting point.

Example:
`
use Phalcon\Http\Client\Request;
use Phalcon\Http\Client\Request\Exception;
use Phalcon\Http\Client\Response;
use Phalcon\Http\Client\Response\Exception;

$request = new Request($options); // Request should use available provide like curl, stream, etc.
$response = $client->post($uri,$data,$options); // should return Response object
`

@niden check above example from @juliusiqbal

@mobarokhossain as @niden already said, an HTTP client is outside the scope of phalcon. There is no point reinventing the wheel when the defacto library is guzzle. Its PSR-7 compliant, actively maintained, filled with features (such as concurrent requests) and overall a great library.

Just composer require guzzlehttp/guzzle and

$client = new \GuzzleHttp\Client();
echo $client->request('GET', 'https://phalconphp.com/en/')->getBody();

I want to close this issue because I don't want a bunch of these lying around. I'd like to add support for anything/everything at some point, but keeping the issue open doesn't help that. :) If anyone wants to get started, I'd love that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linxlad picture linxlad  路  3Comments

bestirani2 picture bestirani2  路  3Comments

sharptry picture sharptry  路  3Comments

TimurFlush picture TimurFlush  路  3Comments

fonqing picture fonqing  路  3Comments