ajayvohra2005 / hack-http-client
HTTP client implementation in Hack language
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Hack
Requires
- hhvm: ^4.132
- ajayvohra2005/hack-promises: ^1.0.0
- hhvm/hhvm-autoload: ^3.3
Requires (Dev)
- facebook/fbexpect: ^2.8
- hhvm/hacktest: ^2.2
- hhvm/hhast: ^4.123
README
Overview
This project implements an HTTP Client in Hack.
- Simple HTTP Client interface
- Synchronous and asynchronous requests
- Middleware support
Requirements
HHVM 4.132 and above.
Installation
-
Git clone this repository
-
Install composer
-
In the root directory of this repository, run the command
composer install
To use this package,
composer require ajayvohra2005/hack-http
Running Tests
Testing uses a mock HTTP server written in Node.js. The project was tested with Node.js version v17.0.1. After installation of Node.js and this project, run the following command in the root directory of this repository:
./vendor/bin/hacktest tests/
Quick Start Example
use namespace HackHttp\Message as HM;
use namespace HackHttp\Client as HC;
<<__EntryPoint>>
function quick_start(): void
{
require_once(__DIR__.'/../vendor/autoload.hack');
\Facebook\AutoloadMap\initialize();
$client = new HC\Client();
// Send a synchronous request.
$response = $client->request('GET', 'https://docs.hhvm.com/hack/');
echo $response->getStatusCode(); // 200
echo $response->getHeaderLine('content-type'); // 'text/html'
echo $response->getBody()->__toString(); // <!DOCTYPE html><html>...
// Send an asynchronous request.
$request = new HM\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then( (mixed $response): void ==> {
if($response is HM\Response) {
echo 'I completed! ' . $response->getBody()->__toString();
}
});
$promise->wait();
}
License
Hack Http package is made available under the MIT License (MIT). Please see License File for more information.
Acknowledgements
The Guzzle, PHP HTTP Client and PSR-7 Message Implementation projects inspired this code.