check https://github.com/guzzle/guzzle
you can use Phalcon's implementation of the PSR-7 HTTP messaging with guzzle's client
example
use Phalcon\Http\Message\ServerRequest;
use Phalcon\Http\Message\Uri;
use GuzzleHttp\Client;
$uri = new Uri('https://jsonplaceholder.typicode.com/posts');
$request = new ServerRequest();
$request = $request
->withHeader('Content-Type', ['application/json'])
->withMethod('POST')
->withUri($uri)
->withParsedBody([
'title' => 'foo',
'body' => 'bar',
'userId' => 1001,
]);
$client = new Client;
$response = $client->send($request); // GuzzleHttp\Psr7\Response
$body = $response->getBody(); // GuzzleHttp\Psr7\Stream
$contents = $body->getContents(); // string { "id": 101 }
javascript equivalent:
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify({
title: 'foo',
body: 'bar',
userId: 1001,
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
})
.then((response) => response.json())
.then((json) => console.log(json))
you can also check https://github.com/php-curl-class/php-curl-class